Created
November 5, 2008 13:41
-
-
Save jcoglan/22334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
# Inspect the method lookup process like you can in JS.Class | |
# http://jsclass.jcoglan.com/reflection.html | |
# | |
# Array.lookup :any? | |
# #=> [#<UnboundMethod: Enumerable#any?>] | |
# | |
# class Array; def any?; super; end; end | |
# Array.lookup :any? | |
# #=> [#<UnboundMethod: Array#any?>, #<UnboundMethod: Enumerable#any?>] | |
# | |
def lookup(name) | |
name = name.to_sym | |
ancestors.map { |mod| | |
mod.instance_methods(false).map { |method_name| | |
method_name.to_sym | |
}.include?(name) ? | |
mod.instance_method(name) : | |
nil | |
}.compact | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment