To See the Whole Ancestry Of The Method...
Define this in an irb
session:
class Object
def method_ancestry(method_name)
method_ancestors = []
method = method(method_name)
while method
method_ancestors << [method.owner, method.source_location]
method = method.super_method
end
method_ancestors
end
end
For instance, in the Rails console, I can do:
# assuming User is an ActiveRecord class
User.new.method_ancestry(:save)
=> [[ActiveRecord::Suppressor,
["/Users/me/.gem/ruby/2.3.1/gems/activerecord-5.0.1/lib/active_record/suppressor.rb", 40]],
[ActiveRecord::Transactions,
["/Users/me/.gem/ruby/2.3.1/gems/activerecord-5.0.1/lib/active_record/transactions.rb", 317]],
[ActiveRecord::AttributeMethods::Dirty,
["/Users/me/.gem/ruby/2.3.1/gems/activerecord-5.0.1/lib/active_record/attribute_methods/dirty.rb",
21]],
[ActiveRecord::Validations,
["/Users/me/.gem/ruby/2.3.1/gems/activerecord-5.0.1/lib/active_record/validations.rb", 43]],
[ActiveRecord::Persistence,
["/Users/me/.gem/ruby/2.3.1/gems/activerecord-5.0.1/lib/active_record/persistence.rb", 124]]]
This list alone doesn't tell you whether any of the method definitions listed actually call super
or just override their inherited definition. But if you see super
in one of them, it goes to the next one in the list.
If you use this a lot, you might put it in your ~/.irbrc
or ~/.pryrc
.