Skip to content

Commit

Permalink
ruby 1.9 completion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Dec 3, 2009
1 parent d992877 commit d815f1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions irb/completion.rb
Expand Up @@ -116,7 +116,7 @@ module InputCompletor
select_message(receiver, message, candidates)

when /^(\$[^.]*)$/
candidates = global_variables.grep(Regexp.new(Regexp.quote($1)))
candidates = global_variables.grep(Regexp.new(Regexp.quote($1))).map {|e| e.to_s }

when /^((\.?[^.]+)+)\.([^.]*)$/
# variable
Expand All @@ -127,7 +127,7 @@ module InputCompletor
lv = eval("local_variables", bind)
cv = eval("self.class.constants", bind)

if (gv | lv | cv).include?(receiver)
if (gv | lv | cv).map {|e| e.to_s }.include?(receiver)
# foo.func and foo is local var.
candidates = eval("#{receiver}.methods", bind)
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
Expand Down Expand Up @@ -165,9 +165,9 @@ module InputCompletor
select_message(receiver, message, candidates)

else
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind)

(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
eval_string = "methods | private_methods | local_variables | self.class.constants"
candidates = eval(eval_string, bind).map {|e| e.to_s} | ReservedWords
candidates.grep(/^#{Regexp.quote(input)}/)
end
}

Expand Down
7 changes: 6 additions & 1 deletion spec/completion_spec.rb
Expand Up @@ -62,7 +62,7 @@ def tab(input)
end

it "completes symbols" do
tab(':callc').should == [':callcc']
tab(':sprint').should == [':sprintf']
end

it "completes global variables" do
Expand Down Expand Up @@ -90,6 +90,11 @@ def tab(input)
tab('dud').should == ['dude']
end

it "completes a local variable's methods" do
eval('dude = "test"', IRB.current_context.workspace.binding)
tab('dude.unp').should == ['dude.unpack']
end

it "completes reserved words" do
tab('wh').should == %w{when while}
end
Expand Down

0 comments on commit d815f1b

Please sign in to comment.