Skip to content

Instantly share code, notes, and snippets.

@mshirdel
Forked from chad/gist:76951
Last active April 27, 2016 10:19
Show Gist options
  • Save mshirdel/202aa2a0b8ed10d4e4bb to your computer and use it in GitHub Desktop.
Save mshirdel/202aa2a0b8ed10d4e4bb to your computer and use it in GitHub Desktop.
# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
class Fixnum
include Perpetrator
end
p 2.method(:crime)
#<Method: Fixnum(Perpetrator)#crime>
require 'csv'
p CSV.new('string').method(:flock)
# => #<Method: CSV#flock>
CSV.new('string').method(:flock).source_location
# => ["/path/to/ruby/1.9.2-p290/lib/ruby/1.9.1/forwardable.rb", 180]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment