Module: MethodLocator
- Defined in:
- lib/method_locator.rb,
lib/method_locator/version.rb
Overview
MethodLocator finds all method definitions in an object instance, class, or module ancestor chain. This code will make more sense if you understand Ruby’s object model and method lookup path. See README for more information.
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Method Summary collapse
Instance Method Details
#method_lookup_path ⇒ Object
13 14 15 16 |
# File 'lib/method_locator.rb', line 13 def method_lookup_path lookup_path = is_a?(Class) ? class_lookup_path : nonclass_lookup_path insert_modules_into(lookup_path) end |
#methods_for(meth) ⇒ Object
7 8 9 10 11 |
# File 'lib/method_locator.rb', line 7 def methods_for(meth) method_lookup_path.each_with_object([]) do |clazz, matches| matches << clazz.instance_method(meth) if instance_methods_for(clazz).include?(meth) end end |
#only_class_ancestors ⇒ Object
18 19 20 |
# File 'lib/method_locator.rb', line 18 def only_class_ancestors ancestors.grep(Class) end |