Ruby definitely stores such information at runtime, as it is printed in stack traces - but there doesn't seem to be any obvious way of accessing it. Is there a solution? (other than grepping the sources, or passing nonsense arguments to method in hope of getting the stack trace)
views:
47answers:
2
+1
A:
This is the best I could find: http://stackoverflow.com/questions/175655/how-to-find-where-a-ruby-method-is-defined-at-runtime
thomasfedb
2010-06-19 13:54:39
+3
A:
In Ruby 1.9, you have Method#source_location:
require 'yaml'
p YAML.method(:load).source_location => ["C:/Ruby19/lib/ruby/1.9.1/yaml.rb", 132]
It appears there's a request to backport source_location to 1.8 (http://redmine.ruby-lang.org/issues/show/2180), but I'm not sure if/when that will happen.
jason.rickman
2010-06-19 13:55:03