RubyMoney / money-rails

Integration of RubyMoney - Money with Rails
MIT License
1.79k stars 386 forks source link

Define methods on dynamic module #703

Open jbennett opened 2 months ago

jbennett commented 2 months ago

Currently you cannot override the generated methods and access super ie:

class Transaction < ApplicationRecord
  monetize :price_cents

  def price=(value)
    # stuff
   super # NoMethodError
  end
end

This happens because the method is defined on the class directly so their is no super method to call. A solution today is to create an alias (alias :old_price= :price=) before overriding the method as is recommending in issue #507.

Instead, a new module can be created, included into the class, and the methods defined on it allowing super to work as expected.

jbennett commented 2 months ago

Looks like #698 also had issues with sqlite3 and added a ~> 1.4 requirement to the main gemfile.