Skip to content

Deprecate Money#dollars and Money.from_dollars #1153

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sunny
Copy link
Contributor

@sunny sunny commented Jul 25, 2025

The #dollars method assumes the amount is in USD but does nothing to verify that.

Money.new(1_23, "USD").dollars # => 1.23 ✅
Money.new(1_23, "EUR").dollars # => 1.23 🤔

I would like to add a warning to let people know that something is wrong here and so that in the future we can actually raise an error here.

Edit: Calling #dollars and .from_dollars are both now deprecated in favor of #amount and .from_amount.

#
# Synonym of #amount
#
# @return [BigDecimal]
#
# @example
# Money.new(1_00, "USD").dollars # => BigDecimal("1.00")
# Money.new(1_00, "USD").dollars # => BigDecimal("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.

I’ve included a few minor whitespace fixes to harmonize the documentation format.

expect(currency).to receive(:symbol).and_return("€")
expect(Money.new(0, currency).symbol).to eq "€"
it "returns the currency’s symbol" do
expect(Money.new(0, "EUR").symbol).to eq("€")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor simplification for this test so as not to rely on stubs so much.

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.

Thanks, @sunny! You are adding deprecations faster than I can remove the old ones 😂

One question, should we also deprecate the from_dollars method?

alias_method :from_dollars, :from_amount

😊

@Sija
Copy link

Sija commented Jul 30, 2025

I'd go as far as to deprecate the method itself, regardless of the currency used. It's US-centric and potentially confusing as to, why this de-facto alias of #amount method has a different logic depending on the currency context.

@sunny
Copy link
Contributor Author

sunny commented Aug 2, 2025

should we also deprecate the from_dollars method?

Good call. It also doesn’t raise any error if the default currency is not dollars-based.

Money.default_currency = "EUR"
Money.from_dollars(13) # => 13 EUR 🙃

However, the change is rather recent. #1032
What do you think @semmons99?

I'd go as far as to deprecate the method itself.

I’d tend to agree, the #amount method was added 12 years ago as a replacement for #dollars.

I’ll deprecate all the dollars methods if y’all are happy with that 🔥

@sunny sunny changed the title Deprecate Money#dollars when the currency is not USD Deprecate Money#dollars and Money.from_dollar Aug 2, 2025
@sunny sunny changed the title Deprecate Money#dollars and Money.from_dollar Deprecate Money#dollars and Money.from_dollars Aug 8, 2025
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.

3 participants