Skip to content

Warn when using #eql? on zero amounts with different currencies #1155

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

Merged

Conversation

sunny
Copy link
Contributor

@sunny sunny commented Jul 25, 2025

Closes #1122

With this change comparing two zero amounts with different currencies using #eql? triggers a warning:

Money.new(1, "USD").eql?(Money.new(1, "EUR")) #=> false
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> true
#> [DEPRECATION] Comparing 0 USD with 0 EUR using `#eql?` will return false in future versions of Money. Opt-in to the new behavior by setting `Money.strict_eql_compare = true`.

To disable this warning, opt-in to the new behavior so that it always does a strict comparison:

Money.strict_eql_compare = true
Money.new(1, "USD").eql?(Money.new(1, "EUR")) #=> false
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> false

I’m guessing that using a configuration to opt-in can help ease into this new behavior, but I’m not sure this would be the best way to introduce this both a warning and a config. Happy for feedback about this.

@sunny sunny mentioned this pull request Jul 25, 2025
Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this! thanks!

@yukideluxe yukideluxe merged commit 956ece2 into RubyMoney:main Jul 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit equality of zero
2 participants