Created
June 27, 2011 18:27
-
-
Save karthiks/1049442 to your computer and use it in GitHub Desktop.
Finding the Ruby method definition - one that is invoked at runtime.
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
class Fixnum | |
def crime | |
end | |
end | |
p 2.method(:crime) | |
#<Method: Fixnum#crime> #crime() defined in Fixnum class is invoked | |
module Loser | |
def crime | |
end | |
end | |
module Perpetrator | |
def crime | |
end | |
end | |
class Fixnum | |
include Loser | |
include Perpetrator | |
end | |
p 2.method(:crime) | |
#<Method: Fixnum(Perpetrator)#crime> #crime() defined in Perpetrator module is invoked | |
class Fixnum | |
def crime | |
end | |
end | |
p 2.method(:crime) | |
#<Method: Fixnum#crime> #re-defined crime() in Fixnum class is invoked | |
p 2.method(:crime).source_location #shows file full path and line number #From Ruby 1.9 only | |
# => ["/home/karthik/MyRubyProjects/practice/katas/ruby_method_method_test.rb", 22] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment