Skip to content

Commit

Permalink
Re-use Pry::Method.safe_send (todo, move to helper?) [Fixes #529]
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Apr 14, 2012
1 parent 13042b4 commit 5a0f8ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/pry/default_commands/ls.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/pry/method.rb
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/test_default_commands/test_ls.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5a0f8ad

Please sign in to comment.