Skip to content

Instantly share code, notes, and snippets.

@knzconnor
Created December 16, 2008 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save knzconnor/36730 to your computer and use it in GitHub Desktop.
Save knzconnor/36730 to your computer and use it in GitHub Desktop.
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