Skip to content

Conversation

@elfassy
Copy link
Contributor

@elfassy elfassy commented Nov 14, 2025

closes #276

Why

Infinity was never explicitly supported by the money gem, yet was not raising, creating issues like #276

Also some code tries to compare a money object with Infinity, which results in exceptions for currencies with no decimals like JPY, ex:

objects.sort_by{|object| object.price || Float::INFINITY}

What

  • explicitly remove support for Money.new(Float::INFINITY)
  • allow comparing a money object with Float::INFINITY

Before

Money.new(1, "JPY") < Float::INFINITY #=> FloatDomainError: Computation results in 'Infinity' (FloatDomainError)
Money.new(Float::INFINITY) #=> no exceptions

After

Money.new(1, "JPY") < Float::INFINITY #=> true
Money.new(Float::INFINITY) #=> raises ArgumentError


def <=>(other)
return unless other.respond_to?(:to_money)
if other.is_a?(Numeric)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will also speed up significantly comparing with a Numeric by not casting these to money objects

@elfassy elfassy requested a review from JingxianHou November 14, 2025 20:20
@elfassy elfassy force-pushed the infinity-and-beyond branch from 08363a5 to 1dac65f Compare November 14, 2025 20:24
@JingxianHou
Copy link

what's the plan for merging this, once it's merged the existing code that uses infinity will automatically fail in production?

@elfassy
Copy link
Contributor Author

elfassy commented Nov 14, 2025

nothing should be doing Money.new(Infinity) , but if it is, it will be caught by tests before code is merged to prod

Copy link

@ryanquanz ryanquanz left a comment

Choose a reason for hiding this comment

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

All LGTM!

@JingxianHou
Copy link

I understand that it will be caught during local development. However if there is already infinity being used in production, does this change breaks those functionalities?

@elfassy
Copy link
Contributor Author

elfassy commented Nov 20, 2025

@JingxianHou yes this is a breaking change for people using Money.new(Infinity). This will be released in a major gem update (v4). If we want we can split this breaking change from fixing the <=> which can also be released in v3, in addition to a deprecation warning

@elfassy elfassy merged commit 6b1d791 into main Nov 20, 2025
9 checks passed
@elfassy elfassy deleted the infinity-and-beyond branch November 20, 2025 20:42
@elfassy
Copy link
Contributor Author

elfassy commented Nov 20, 2025

moved raising to #476

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.

Is Float::INFINITY a valid Money input?

3 participants