Permalink
Browse files

Re-use Pry::Method.safe_send (todo, move to helper?) [Fixes #529]

  • Loading branch information...
ConradIrwin committed Apr 14, 2012
1 parent 13042b4 commit 5a0f8adcd94a0598459db062f0c4dee38f308707
Showing with 9 additions and 2 deletions.
  1. +4 −2 lib/pry/default_commands/ls.rb
  2. +1 −0 lib/pry/method.rb
  3. +4 −0 test/test_default_commands/test_ls.rb
@@ -87,8 +87,10 @@ def process
if show_ivars
klass = (Module === obj ? obj : obj.class)
- output_section("instance variables", format_variables(:instance_var, grep[Object.instance_method(:instance_variables).bind(obj).call]))
- output_section("class variables", format_variables(:class_var, grep[Class.instance_method(:class_variables).bind(klass).call]))
+ ivars = Pry::Method.safe_send(obj, :instance_variables)
+ kvars = Pry::Method.safe_send(klass, :class_variables)
+ output_section("instance variables", format_variables(:instance_var, ivars))
+ output_section("class variables", format_variables(:class_var, kvars))
end
if show_locals
View
@@ -188,6 +188,7 @@ def all_from_common(obj, method_type, include_super=true)
def safe_send(obj, method, *args, &block)
(Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
end
+ public :safe_send
# Get the singleton classes of superclasses that could define methods on
# the given class object, and any modules they include.
@@ -58,6 +58,10 @@
it "should still work" do
mock_pry("cd Module.new{ def foobie; end }", "ls -M").should =~ /foobie/
end
+
+ it "should work for ivars" do
+ mock_pry("module StigmaT1sm; def foobie; @@gharble = 456; end; end", "Object.new.tap{ |o| o.extend(StigmaT1sm) }.foobie", "cd StigmaT1sm", "ls -i").should =~ /@@gharble/
+ end
end
describe "constants" do

0 comments on commit 5a0f8ad

Please sign in to comment.