Created
October 23, 2008 15:30
-
-
Save Peeja/19070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# klass.first_responder(:method) gives you the Module in klass's inheritance chain which will respond to :method. | |
# klass.all_responders(:method) gives you all of the Modules in klass's inheritance chain which can respond to :method, in order from klass to Kernel. | |
require 'metaid' | |
class Object | |
def first_responder(method) | |
method = method.to_s | |
metaclass.ancestors.find do |mod| | |
mod.instance_methods(false).include? method | |
end | |
end | |
def all_responders(method) | |
method = method.to_s | |
metaclass.ancestors.find_all do |mod| | |
mod.instance_methods(false).include? method | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment