I have a ruby method (deactivate!) that is on an activeRecord class. However, I can't seem to find where that method is declared.
There have been numerous developers on this project, so it could be anywhere. There is a deactivate! on an unrelated class, but it doesn't seem to get called.
Any ideas how to find all the superclasses for an instace, or where to find the code for deactivate!?
In Ruby the method for object can be defined from many places: modules, inheritance, meta-programming, other language's extensions and etc. Imagine that you have installed a lot of gems in your application and every gem potentially can define or redefine method on any object.
early 15c., "regular, systematic treatment of disease," from Latin methodus "way of teaching or going," from Greek methodos "scientific inquiry, method of inquiry, investigation," originally "pursuit, a following after," from meta "in pursuit or quest of" (see meta-) + hodos "a method, system; a way or manner" (of ...
First question would be: is it an actual method? Does obj.method(:deactivate!)
raise an error?
If it doesn't, then you can use Method#source_location
(in Ruby 1.9 only, and backports
can't support it):
obj.method(:deactivate!).source_location
If it does raise a NoMethodError
, it is handled via method_missing
. This makes it hard to track. If it accepts arguments, I'd try sending the wrong type and using the backtrace of the raised exception.
Are you using state_machine
? If you have an event transition called :deactivate
, the model will have the method #deactivate!
created automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With