gist: 36730 Download_button fork
public
Description:
Determining where in the inheritance chain a method is defined (ruby).
Public Clone URL: git://gist.github.com/36730.git
method_defined_where.rb
1
2
3
4
5
6
7
8
9
10
11
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

Owner

timocratic

Forks

Revisions