Created
December 16, 2008 19:16
-
-
Save knzai/36730 to your computer and use it in GitHub Desktop.
Determining where in the inheritance chain a method is defined (ruby).
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
def Object.method_defined_where(method) | |
self.ancestors.detect { |a| a.methods(false).include?(method.to_s) } | |
end | |
#Usage - define in your .irbrc and then: | |
#File.method_defined_where('read') | |
#=> IO | |
#Alternatively it has been added to my copy of utility_belt: http://github.com/timocratic/utility-belt/commit/74397c4f8be135cf46f65ca509ddb90e2e47799e | |
#For something more in depth, use http://github.com/spicycode/the-inspector/tree/master/spec/unit/inspector_spec.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment