mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/irb.rb: typo. Thanks, Giles Bowkett.
* lib/irb/completion.rb: support Ruby1.9 changing return value String to Symbol for Object#methods, etc. [ruby-dev:31148]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
616f4d3385
commit
7756f1df18
3 changed files with 30 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Fri Jul 6 19:55:10 2007 Keiju Ishitsuka <keiju@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/irb.rb: typo. Thanks, Giles Bowkett.
|
||||||
|
|
||||||
|
* lib/irb/completion.rb: support Ruby1.9 changing return value
|
||||||
|
String to Symbol for Object#methods, etc. [ruby-dev:31148].
|
||||||
|
|
||||||
Fri Jul 6 18:20:50 2007 Koichi Sasada <ko1@atdot.net>
|
Fri Jul 6 18:20:50 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* bootstraptest/runner.rb: fix load path.
|
* bootstraptest/runner.rb: fix load path.
|
||||||
|
|
|
@ -85,7 +85,7 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# irb interpriter main routine
|
# irb interpreter main routine
|
||||||
#
|
#
|
||||||
class Irb
|
class Irb
|
||||||
def initialize(workspace = nil, input_method = nil, output_method = nil)
|
def initialize(workspace = nil, input_method = nil, output_method = nil)
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
require "readline"
|
require "readline"
|
||||||
|
|
||||||
|
X=1
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
module InputCompletor
|
module InputCompletor
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Regexp.instance_methods(true)
|
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^([^\]]*\])\.([^.]*)$/
|
when /^([^\]]*\])\.([^.]*)$/
|
||||||
|
@ -53,7 +55,7 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Array.instance_methods(true)
|
candidates = Array.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^([^\}]*\})\.([^.]*)$/
|
when /^([^\}]*\})\.([^.]*)$/
|
||||||
|
@ -61,7 +63,8 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
|
candidates = Proc.instance_methods.collect{|m| m.to_s}
|
||||||
|
candidates |= Hash.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(:[^:.]*)$/
|
when /^(:[^:.]*)$/
|
||||||
|
@ -77,7 +80,7 @@ module IRB
|
||||||
when /^::([A-Z][^:\.\(]*)$/
|
when /^::([A-Z][^:\.\(]*)$/
|
||||||
# Absolute Constant or class methods
|
# Absolute Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
candidates = Object.constants
|
candidates = Object.constants.collect{|m| m.to_s}
|
||||||
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
|
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
|
||||||
|
|
||||||
when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
|
when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
|
||||||
|
@ -85,7 +88,8 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($4)
|
message = Regexp.quote($4)
|
||||||
begin
|
begin
|
||||||
candidates = eval("#{receiver}.constants | #{receiver}.methods", bind)
|
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
||||||
|
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
|
@ -96,7 +100,7 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
candidates = Symbol.instance_methods(true)
|
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
|
when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
|
||||||
|
@ -105,7 +109,7 @@ module IRB
|
||||||
message = Regexp.quote($5)
|
message = Regexp.quote($5)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
|
@ -117,14 +121,15 @@ module IRB
|
||||||
message = Regexp.quote($2)
|
message = Regexp.quote($2)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
candidates = eval(receiver, bind).methods
|
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(\$[^.]*)$/
|
when /^(\$[^.]*)$/
|
||||||
candidates = global_variables.grep(Regexp.new(Regexp.quote($1)))
|
regmessage = Regexp.new(Regexp.quote($1))
|
||||||
|
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
||||||
|
|
||||||
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
||||||
when /^((\.?[^.]+)+)\.([^.]*)$/
|
when /^((\.?[^.]+)+)\.([^.]*)$/
|
||||||
|
@ -132,17 +137,17 @@ module IRB
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($3)
|
message = Regexp.quote($3)
|
||||||
|
|
||||||
gv = eval("global_variables", bind)
|
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
||||||
lv = eval("local_variables", bind)
|
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
||||||
cv = eval("self.class.constants", bind)
|
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
|
||||||
|
|
||||||
if (gv | lv | cv).include?(receiver)
|
if (gv | lv | cv).include?(receiver)
|
||||||
# foo.func and foo is local var.
|
# foo.func and foo is local var.
|
||||||
candidates = eval("#{receiver}.methods", bind)
|
candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
|
||||||
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
|
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
|
||||||
# Foo::Bar.func
|
# Foo::Bar.func
|
||||||
begin
|
begin
|
||||||
candidates = eval("#{receiver}.methods", bind)
|
candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
|
||||||
rescue Exception
|
rescue Exception
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
|
@ -157,7 +162,7 @@ module IRB
|
||||||
end
|
end
|
||||||
next if name != "IRB::Context" and
|
next if name != "IRB::Context" and
|
||||||
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
||||||
candidates.concat m.instance_methods(false)
|
candidates.concat m.instance_methods(false).collect{|m| m.to_s}
|
||||||
}
|
}
|
||||||
candidates.sort!
|
candidates.sort!
|
||||||
candidates.uniq!
|
candidates.uniq!
|
||||||
|
@ -170,11 +175,11 @@ module IRB
|
||||||
receiver = ""
|
receiver = ""
|
||||||
message = Regexp.quote($1)
|
message = Regexp.quote($1)
|
||||||
|
|
||||||
candidates = String.instance_methods(true)
|
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
else
|
else
|
||||||
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind)
|
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
|
||||||
|
|
||||||
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue