0

Duplicate: How To Find Where A Ruby Method Is Defined At Runtime


With a given object, is it possible to find out where each method was defined?
Community
  • 1
  • 1
troelskn
  • 115,121
  • 27
  • 131
  • 155

1 Answers1

0

After the fact, it will be pretty tough, but you can use a hook method to observe the line numbers where a method is defined.

class X < Object

  def X.method_added(symbol)
    puts "adding method #{symbol} to class X from #{caller(0)}"
  end

end


class X
  def a_method
  end
end
Nigel Thorne
  • 21,158
  • 3
  • 35
  • 51
David Nehme
  • 21,379
  • 8
  • 78
  • 117