mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Re-use Pry::Method.safe_send (todo, move to helper?) [Fixes #529]
This commit is contained in:
parent
13042b4be8
commit
5a0f8adcd9
3 changed files with 9 additions and 2 deletions
|
@ -87,8 +87,10 @@ class Pry
|
|||
|
||||
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
|
||||
|
|
|
@ -188,6 +188,7 @@ class Pry
|
|||
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 @@ describe "ls" do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue