Skip to content

Conversation

pranavbabu
Copy link
Contributor

Fix for #1109

Copy link
Member

@sunny sunny left a comment

Choose a reason for hiding this comment

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

Could you add an entry to the changelog as well? 🙏🏻

# @example
# 2 * Money.new(10) #=> #<Money @fractional=20>
def coerce(other)
raise TypeError, "Cannot divide Numeric by Money" if caller_locations(1,1).first.label == "/"
Copy link
Member

@sunny sunny Jul 23, 2025

Choose a reason for hiding this comment

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

Relying on the caller locations may not be the most robust way to handle this and looks like it could imply a slight performance penalty. Would there be another way to do this?

if value.is_a?(self.class)
fractional / as_d(value.exchange_to(currency).fractional).to_f
exchanged = value.exchange_to(currency)
raise ZeroDivisionError, "divided by Money(0)" if exchanged.zero?
Copy link
Member

@sunny sunny Jul 23, 2025

Choose a reason for hiding this comment

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

Could you add specs for each of these raised errors? 🙏🏻

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.

2 participants