super() への呼び出しが何を呼び出すかを決定することが可能
概要
問題をデバッグしようとしていますが、これがスーパーに呼び出すクラスが https://github.com/rails/rails/blob/main/activemodel/lib/active_model/api を呼び出すことになるかどうかを判断する方法を知りたいです.rb#L83
そこにてこ入れして show-source を実行しましたが、self.class.includeed_modules の呼び出しが正確かどうかはわかりません。
[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]
推測して caller を実行することもできますが、それは非常に洗練されていない解決策のように思えます。スーパーが次にどこへ向かうのかをどうやって知ることができるでしょうか?
解決策
SalesOrder.instance_method(:initialize).super_method
…または実際には ActiveModel::API だと思います。