Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Determining where in the inheritance chain a method is defined (ruby).
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