-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define methods on dynamic module #703
base: main
Are you sure you want to change the base?
Conversation
Currently you cannot override the generated methods and access super ie: ```ruby monetize :price_cents def price=(value) # stuff super # NoMethodError 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 RubyMoney#507. Instead, a new module can be created, included into the class, and the methods defined on it allowing `super` to work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Can you add an entry to the CHANGELOG as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests don’t seem to run though, but it doesn’t seem to be linked to your changes 🤔
Looks like #698 also had issues with sqlite3 and added a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Currently you cannot override the generated methods and access super ie:
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.