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,39 +2,42 @@ 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
|
if str.nil?
|
||||||
|
from_binding(target)
|
||||||
def self.from_module(klass, name)
|
elsif str.to_s =~ /(\S+)\#(\S+)\Z/
|
||||||
new(klass.instance_method(name)) rescue nil
|
context, meth_name = $1, $2
|
||||||
end
|
from_module(target.eval(context), meth_name)
|
||||||
|
elsif str.to_s =~ /(\S+)\.(\S+)\Z/
|
||||||
def self.from_str(str, target=TOPLEVEL_BINDING, options={})
|
context, meth_name = $1, $2
|
||||||
if str.nil?
|
from_obj(target.eval(context), meth_name)
|
||||||
from_binding(target)
|
elsif options[:instance]
|
||||||
elsif str.to_s =~ /(\S+)\#(\S+)\Z/
|
new(target.eval("instance_method(:#{str})")) rescue nil
|
||||||
context, meth_name = $1, $2
|
elsif options[:methods]
|
||||||
from_module(target.eval(context), meth_name)
|
new(target.eval("method(:#{str})")) rescue nil
|
||||||
elsif str.to_s =~ /(\S+)\.(\S+)\Z/
|
else
|
||||||
context, meth_name = $1, $2
|
from_str(str, target, :instance => true) ||
|
||||||
from_obj(target.eval(context), meth_name)
|
from_str(str, target, :methods => true)
|
||||||
elsif options[:instance]
|
end
|
||||||
new(target.eval("instance_method(:#{str})")) rescue nil
|
|
||||||
elsif options[:methods]
|
|
||||||
new(target.eval("method(:#{str})")) rescue nil
|
|
||||||
else
|
|
||||||
from_str(str, target, :instance => true) ||
|
|
||||||
from_str(str, target, :methods => true)
|
|
||||||
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
|
||||||
else
|
else
|
||||||
new(b.eval("method(:#{meth_name})"))
|
new(b.eval("method(:#{meth_name})"))
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue