mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Use ::Kernel.__method__ so that we can work on BasicObject
This commit is contained in:
parent
baaa85a15c
commit
f62ced6f38
4 changed files with 31 additions and 3 deletions
|
@ -40,7 +40,7 @@ class Pry
|
|||
end
|
||||
|
||||
def internal_binding?(target)
|
||||
m = target.eval("__method__").to_s
|
||||
m = target.eval("::Kernel.__method__").to_s
|
||||
# class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
|
||||
["__binding__", "__pry__", "class_eval"].include?(m)
|
||||
end
|
||||
|
|
|
@ -62,12 +62,16 @@ class Pry
|
|||
# @return [Pry::Method, nil]
|
||||
#
|
||||
def from_binding(b)
|
||||
meth_name = b.eval('__method__')
|
||||
meth_name = b.eval('::Kernel.__method__')
|
||||
if [:__script__, nil].include?(meth_name)
|
||||
nil
|
||||
else
|
||||
method = begin
|
||||
new(Object.instance_method(:method).bind(b.eval("self")).call(meth_name))
|
||||
if Object === b.eval('self')
|
||||
new(Kernel.instance_method(:method).bind(b.eval("self")).call(meth_name))
|
||||
else
|
||||
new(b.eval('class << self; self; end.instance_method(::Kernel.__method__).bind(self)'))
|
||||
end
|
||||
rescue NameError, NoMethodError
|
||||
Disowned.new(b.eval('self'), meth_name.to_s)
|
||||
end
|
||||
|
|
|
@ -41,6 +41,18 @@ describe "whereami" do
|
|||
Object.remove_const(:Cor)
|
||||
end
|
||||
|
||||
if defined?(BasicObject)
|
||||
it 'should work in BasicObjects' do
|
||||
cor = Class.new(BasicObject) do
|
||||
def blimey!
|
||||
::Kernel.binding # omnom
|
||||
end
|
||||
end.new.blimey!
|
||||
|
||||
pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/
|
||||
end
|
||||
end
|
||||
|
||||
it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
|
||||
class Cor
|
||||
def blimey!
|
||||
|
|
|
@ -119,6 +119,18 @@ describe Pry::Method do
|
|||
m.source_line.should == b.line
|
||||
m.name.should == "gag"
|
||||
end
|
||||
|
||||
if defined? BasicObject
|
||||
it "should find the right method from a BasicObject" do
|
||||
a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end }
|
||||
|
||||
m = Pry::Method.from_binding(a.new.gag)
|
||||
|
||||
m.owner.should == a
|
||||
m.source_file.should == __FILE__
|
||||
m.source_line.should == a.line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'super' do
|
||||
|
|
Loading…
Reference in a new issue