Skip to content

Commit 324bae2

Browse files
authored
Merge pull request #1150 from RubyMoney/jl-currency-as-string-deprecation
remove Money#currency_as_string and Money#currency_as_string= deprecated methods
2 parents b676d90 + 5686730 commit 324bae2

File tree

4 files changed

+5
-67
lines changed

4 files changed

+5
-67
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
## Upcoming 7.0.0.alpha
44

5-
- **Breaking change**: Require Ruby >= 3.1 and I18n ~> 1.9
5+
- **Breaking change**: Require Ruby >= 3.1 and i18n ~> 1.9
66
- **Breaking change**: Remove deprecated methods:
7-
- `Money.infinite_precision`
8-
- `Money.infinite_precision=`
7+
- `Money.infinite_precision`.
8+
- `Money.infinite_precision=`.
9+
- `Money#currency_as_string`.
10+
- `Money#currency_as_string=`.
911
- **Breaking change**: Default currency is now `nil` instead of `USD`. If you want to keep the previous behavior, set `Money.default_currency = Money::Currency.new("USD")` in your initializer. Initializing a Money object will raise a `Currency::NoCurrency` if no currency is set.
1012
- **Breaking change**: The default rounding mode has changed from `BigDecimal::ROUND_HALF_EVEN` to `BigDecimal::ROUND_HALF_UP`. Set it explicitly using `Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN` to keep the previous behavior.
1113
- **Potential breaking change**: Fix RSD (Serbian Dinar) formatting to be like `12.345,42 RSD`

lib/money/money.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -397,31 +397,6 @@ def amount
397397
to_d
398398
end
399399

400-
# Return string representation of currency object
401-
#
402-
# @return [String]
403-
#
404-
# @example
405-
# Money.new(100, :USD).currency_as_string #=> "USD"
406-
def currency_as_string
407-
warn "[DEPRECATION] `currency_as_string` is deprecated. Please use `.currency.to_s` instead."
408-
currency.to_s
409-
end
410-
411-
# Set currency object using a string
412-
#
413-
# @param [String] val The currency string.
414-
#
415-
# @return [Money::Currency]
416-
#
417-
# @example
418-
# Money.new(100).currency_as_string("CAD") #=> #<Money::Currency id: cad>
419-
def currency_as_string=(val)
420-
warn "[DEPRECATION] `currency_as_string=` is deprecated - Money instances are immutable." \
421-
" Please use `with_currency` instead."
422-
@currency = Currency.wrap(val)
423-
end
424-
425400
# Returns a Integer hash value based on the +fractional+ and +currency+ attributes
426401
# in order to use functions like & (intersection), group_by, etc.
427402
#

sig/lib/money/money.rbs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -346,24 +346,6 @@ class Money
346346
#
347347
def amount: () -> BigDecimal
348348

349-
# Return string representation of currency object
350-
#
351-
# @return [String]
352-
#
353-
# @example
354-
# Money.new(100, :USD).currency_as_string #=> "USD"
355-
def currency_as_string: () -> string
356-
357-
# Set currency object using a string
358-
#
359-
# @param [String] val The currency string.
360-
#
361-
# @return [Money::Currency]
362-
#
363-
# @example
364-
# Money.new(100).currency_as_string("CAD") #=> #<Money::Currency id: cad>
365-
def currency_as_string=: (string val) -> Currency
366-
367349
# Returns a Integer hash value based on the +fractional+ and +currency+ attributes
368350
# in order to use functions like & (intersection), group_by, etc.
369351
#

spec/money_spec.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -632,27 +632,6 @@ def m.amount
632632
end
633633
end
634634

635-
describe "#currency_as_string" do
636-
it "returns the iso_code of the currency object" do
637-
expect(Money.new(1_00, "USD").currency_as_string).to eq "USD"
638-
expect(Money.new(1_00, "EUR").currency_as_string).to eq "EUR"
639-
end
640-
end
641-
642-
describe "#currency_as_string=" do
643-
it "sets the currency object using the provided string leaving cents intact" do
644-
money = Money.new(100_00, "USD")
645-
646-
money.currency_as_string = "EUR"
647-
expect(money.currency).to eq Money::Currency.new("EUR")
648-
expect(money.cents).to eq 100_00
649-
650-
money.currency_as_string = "YEN"
651-
expect(money.currency).to eq Money::Currency.new("YEN")
652-
expect(money.cents).to eq 100_00
653-
end
654-
end
655-
656635
describe "#hash=" do
657636
it "returns the same value for equal objects" do
658637
expect(Money.new(1_00, "EUR").hash).to eq Money.new(1_00, "EUR").hash

0 commit comments

Comments
 (0)