1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Completion for instance and class variables.

Pry is now able to complete variable names for instance and class variables, as
well as being able to complete methods and the like on these variables.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
This commit is contained in:
Yorick Peterse 2012-06-19 12:32:03 +02:00
parent b707d84c6a
commit a36322a6bc
2 changed files with 35 additions and 1 deletions

View file

@ -180,7 +180,15 @@ class Pry
select_message(receiver, message, candidates)
else
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates = eval(
"methods | private_methods | local_variables | " \
"self.class.constants | instance_variables",
bind
).collect{|m| m.to_s}
if eval("respond_to?(:class_variables)", bind)
candidates += eval("class_variables", bind).collect { |m| m.to_s }
end
(candidates|ReservedWords|commands).grep(/^#{Regexp.quote(input)}/)
end

View file

@ -22,5 +22,31 @@ describe Pry::InputCompleter do
lambda{ completer.call "a.to_s." }.should.not.raise Exception
end
end
it 'should complete instance variables' do
object = Object.new
object.instance_variable_set(:'@name', 'Pry')
object.class.class_variable_set(:'@@number', 10)
object.instance_variables.include?(:'@name').should == true
object.class.class_variables.include?(:'@@number').should == true
completer = Pry::InputCompleter.build_completion_proc(
Pry.binding_for(object)
)
# Complete instance variables.
completer.call('@na').include?('@name').should == true
completer.call('@name.down').include?('@name.downcase').should == true
# Complete class variables.
completer = Pry::InputCompleter.build_completion_proc(
Pry.binding_for(object.class)
)
completer.call('@@nu').include?('@@number').should == true
completer.call('@@number.cl').include?('@@number.class').should == true
end
end