Method: Pry::Method.from_str
- Defined in:
- lib/pry/method.rb
.from_str(name, target = TOPLEVEL_BINDING, options = {}) ⇒ Pry::Method?
Given a string representing a method name and optionally a binding to search in, find and return the requested method wrapped in a Pry::Method instance.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pry/method.rb', line 43 def from_str(name, target = TOPLEVEL_BINDING, = {}) if name.nil? nil elsif name.to_s =~ /(.+)\#(\S+)\Z/ context = Regexp.last_match(1) meth_name = Regexp.last_match(2) from_module(target.eval(context), meth_name, target) elsif name.to_s =~ /(.+)(\[\])\Z/ context = Regexp.last_match(1) meth_name = Regexp.last_match(2) from_obj(target.eval(context), meth_name, target) elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/ context = Regexp.last_match(1) meth_name = Regexp.last_match(3) from_obj(target.eval(context), meth_name, target) elsif [:instance] from_module(target.eval("self"), name, target) elsif [:methods] from_obj(target.eval("self"), name, target) else from_str(name, target, instance: true) || from_str(name, target, methods: true) end rescue Pry::RescuableException nil end |