Wednesday, March 29, 2017

Ruby related: Inspecting methods, Getting Source Location

http://stackoverflow.com/questions/4664578/how-do-i-inspect-the-methods-of-a-ruby-object
obj.class.instance_methods(false)

http://stackoverflow.com/questions/3393096/how-can-i-get-source-code-of-a-method-dynamically-and-also-which-file-is-this-me

 Use source_location:
class A
  def foo
  end
end
file, line = A.instance_method(:foo).source_location
# or
file, line = A.new.method(:foo).source_location
puts "Method foo is defined in #{file}, line #{line}"
# => "Method foo is defined in temp.rb, line 2"

No comments:

Post a Comment

Followers

Blog Archive