mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Lazily evaluate candidates locals
https://github.com/ruby/irb/commit/19a2fcbd87
This commit is contained in:
parent
7be5e9b971
commit
7cafe09aec
1 changed files with 32 additions and 22 deletions
|
@ -171,10 +171,10 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = $3
|
message = $3
|
||||||
|
|
||||||
candidates = String.instance_methods.collect{|m| m.to_s}
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"String.#{message}"
|
"String.#{message}"
|
||||||
else
|
else
|
||||||
|
candidates = String.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -183,10 +183,10 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = $2
|
message = $2
|
||||||
|
|
||||||
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"Regexp.#{message}"
|
"Regexp.#{message}"
|
||||||
else
|
else
|
||||||
|
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -195,10 +195,10 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = $2
|
message = $2
|
||||||
|
|
||||||
candidates = Array.instance_methods.collect{|m| m.to_s}
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"Array.#{message}"
|
"Array.#{message}"
|
||||||
else
|
else
|
||||||
|
candidates = Array.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -207,29 +207,33 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = $2
|
message = $2
|
||||||
|
|
||||||
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
|
|
||||||
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
["Proc.#{message}", "Hash.#{message}"]
|
["Proc.#{message}", "Hash.#{message}"]
|
||||||
else
|
else
|
||||||
|
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
|
||||||
|
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, proc_candidates | hash_candidates)
|
select_message(receiver, message, proc_candidates | hash_candidates)
|
||||||
end
|
end
|
||||||
|
|
||||||
when /^(:[^:.]*)$/
|
when /^(:[^:.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
return nil if doc_namespace
|
if doc_namespace
|
||||||
sym = $1
|
nil
|
||||||
candidates = Symbol.all_symbols.collect do |s|
|
else
|
||||||
":" + s.id2name.encode(Encoding.default_external)
|
sym = $1
|
||||||
rescue EncodingError
|
candidates = Symbol.all_symbols.collect do |s|
|
||||||
# ignore
|
":" + s.id2name.encode(Encoding.default_external)
|
||||||
|
rescue EncodingError
|
||||||
|
# ignore
|
||||||
|
end
|
||||||
|
candidates.grep(/^#{Regexp.quote(sym)}/)
|
||||||
end
|
end
|
||||||
candidates.grep(/^#{Regexp.quote(sym)}/)
|
|
||||||
|
|
||||||
when /^::([A-Z][^:\.\(\)]*)$/
|
when /^::([A-Z][^:\.\(\)]*)$/
|
||||||
# Absolute Constant or class methods
|
# Absolute Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
|
|
||||||
candidates = Object.constants.collect{|m| m.to_s}
|
candidates = Object.constants.collect{|m| m.to_s}
|
||||||
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
candidates.find { |i| i == receiver }
|
candidates.find { |i| i == receiver }
|
||||||
else
|
else
|
||||||
|
@ -240,15 +244,17 @@ module IRB
|
||||||
# Constant or class methods
|
# Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = $2
|
message = $2
|
||||||
begin
|
|
||||||
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
|
||||||
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
|
||||||
rescue Exception
|
|
||||||
candidates = []
|
|
||||||
end
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"#{receiver}::#{message}"
|
"#{receiver}::#{message}"
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
|
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
||||||
|
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
||||||
|
rescue Exception
|
||||||
|
candidates = []
|
||||||
|
end
|
||||||
|
|
||||||
select_message(receiver, message, candidates, "::")
|
select_message(receiver, message, candidates, "::")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -258,10 +264,10 @@ module IRB
|
||||||
sep = $2
|
sep = $2
|
||||||
message = $3
|
message = $3
|
||||||
|
|
||||||
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"Symbol.#{message}"
|
"Symbol.#{message}"
|
||||||
else
|
else
|
||||||
|
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates, sep)
|
select_message(receiver, message, candidates, sep)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -273,6 +279,7 @@ module IRB
|
||||||
|
|
||||||
begin
|
begin
|
||||||
instance = eval(receiver, bind)
|
instance = eval(receiver, bind)
|
||||||
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"#{instance.class.name}.#{message}"
|
"#{instance.class.name}.#{message}"
|
||||||
else
|
else
|
||||||
|
@ -283,7 +290,7 @@ module IRB
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
candidates = []
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -305,7 +312,7 @@ module IRB
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
candidates = []
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -313,6 +320,7 @@ module IRB
|
||||||
# global var
|
# global var
|
||||||
gvar = $1
|
gvar = $1
|
||||||
all_gvars = global_variables.collect{|m| m.to_s}
|
all_gvars = global_variables.collect{|m| m.to_s}
|
||||||
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
all_gvars.find{ |i| i == gvar }
|
all_gvars.find{ |i| i == gvar }
|
||||||
else
|
else
|
||||||
|
@ -356,6 +364,7 @@ module IRB
|
||||||
candidates.sort!
|
candidates.sort!
|
||||||
candidates.uniq!
|
candidates.uniq!
|
||||||
end
|
end
|
||||||
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
rec_class = rec.is_a?(Module) ? rec : rec.class
|
rec_class = rec.is_a?(Module) ? rec : rec.class
|
||||||
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
|
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
|
||||||
|
@ -370,6 +379,7 @@ module IRB
|
||||||
message = $1
|
message = $1
|
||||||
|
|
||||||
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
||||||
|
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
"String.#{candidates.find{ |i| i == message }}"
|
"String.#{candidates.find{ |i| i == message }}"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue