mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
let from_str delegate to from_binding
This commit is contained in:
parent
6133f4a831
commit
9810589d17
1 changed files with 34 additions and 31 deletions
|
@ -2,15 +2,8 @@ class Pry
|
||||||
class Method
|
class Method
|
||||||
include RbxMethod if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
include RbxMethod if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
||||||
|
|
||||||
def self.from_obj(obj, name)
|
class << self
|
||||||
new(obj.method(name)) rescue nil
|
def from_str(str, target=TOPLEVEL_BINDING, options={})
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_module(klass, name)
|
|
||||||
new(klass.instance_method(name)) rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_str(str, target=TOPLEVEL_BINDING, options={})
|
|
||||||
if str.nil?
|
if str.nil?
|
||||||
from_binding(target)
|
from_binding(target)
|
||||||
elsif str.to_s =~ /(\S+)\#(\S+)\Z/
|
elsif str.to_s =~ /(\S+)\#(\S+)\Z/
|
||||||
|
@ -29,7 +22,7 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_binding(b)
|
def from_binding(b)
|
||||||
meth_name = b.eval('__method__')
|
meth_name = b.eval('__method__')
|
||||||
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
|
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
|
||||||
nil
|
nil
|
||||||
|
@ -38,6 +31,16 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_module(nodule, name)
|
||||||
|
new(nodule.instance_method(name)) rescue nil
|
||||||
|
end
|
||||||
|
alias from_class from_module
|
||||||
|
|
||||||
|
def from_obj(obj, name)
|
||||||
|
new(obj.method(name)) rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(method)
|
def initialize(method)
|
||||||
@method = method
|
@method = method
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue