Search code examples
ruby-on-railsruby

possible to determine what this call to super() will be calling


I'm trying to debug an issue and would like to know how I could determine which class this will call to super will be calling https://github.com/rails/rails/blob/main/activemodel/lib/active_model/api.rb#L83

I have put a pry in there and ran show-source and I'm not sure if calling self.class.included_modules will be accurate.

[3] pry(#<SalesOrder>)> self.class.included_modules
=> [ActiveModel::Model,
 ActiveModel::API,
 ActiveModel::AttributeAssignment,
 ActiveModel::ForbiddenAttributesProtection,
 ActiveModel::Conversion,
 ActiveModel::Validations::HelperMethods,
 ActiveSupport::Callbacks,
 ActiveModel::Validations,
 ActiveSupport::Dependencies::RequireDependency,
 ActiveSupport::ToJsonWithActiveSupportEncoder,
 PP::ObjectMixin,
 ActiveSupport::Tryable,
 JSON::Ext::Generator::GeneratorMethods::Object,
 Kernel]

I could guess and run caller but that seems like a very inelegant solution. How could I tell where super is going next?


Solution

  • SalesOrder.instance_method(:initialize).super_method
    

    ...or I suppose actually ActiveModel::API.