Created
February 7, 2012 20:19
-
-
Save acook/1761702 to your computer and use it in GitHub Desktop.
Which class is a method defined on?
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
module Which | |
def which symbol | |
klass = self.is_a?(Class) ? self : self.class | |
reciever = klass.ancestors.select do |dad| | |
dad.instance_methods.include?(symbol) || dad.methods.include?(symbol) | |
end.last | |
end | |
end | |
Object.send :extend, Which |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment