Skip to content

Conversation

@c960657
Copy link
Contributor

@c960657 c960657 commented Jan 17, 2026

Instead of hardcoded support for four specific currencies (CAD, EUR, GBP, USD), allow users to decide which currencies to define helper methods for.

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.

I love the idea of simplifying the code and removing these special cases for certain currencies. 😍

However I’m not sure we want to encourage people to write their own shortcut methods and have to maintain this, knowing that adding methods this way could possibly break future needs.

I think I’d rather encourage people using the Turkish lira to use Money.new(1_00, "TRY") or 1.to_money("TRY") than to add a new Money.try(1) method.

# Money.us_dollar(100.1).format #=> "$1.001"
# Money.us_dollar(100.1).format(rounded_infinite_precision: true) #=> "$1"
# Money.us_dollar(100.9).format(rounded_infinite_precision: true) #=> "$1.01"
# Money.new(100.1, "USD").format #=> "$1.001"
Copy link
Member

Choose a reason for hiding this comment

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

These are not the same. Money.new accepts cents, while Money.us_dollar accepts a full amount.

Money.new(100.1, "USD").format # => "$ 1.00"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT both accept cents?

def us_dollar(cents)
new(cents, "USD")
end

@c960657
Copy link
Contributor Author

c960657 commented Jan 28, 2026

Good point about #try. Perhaps the constructor methods could be prefixed with from_, i.e. from_usd, from_eur, from_us_dollar, etc. in order to make the names more unique and for consistency with from_amount.

But I tend to agree that such helpers are not the way to go. In a multi-currency application you would usually not use currency-specific method names. I would primarily use them in tests for better readability. But users can easily monkey-patch helpers for their preferred currencies.

If helpers are deemed unnecessary, I think the existing helpers for USD, EUR and CAD should be deprecated and eventually removed.

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