Skip to content
Browse files

add optional currency argument to Numeric#to_money

  • Loading branch information...
1 parent b93de1a commit bad6f51412590854f392a307a86d917dff45776c @semmons99 semmons99 committed
Showing with 7 additions and 2 deletions.
  1. +2 −2 lib/money/core_extensions.rb
  2. +5 −0 test/core_extensions_spec.rb
View
4 lib/money/core_extensions.rb
@@ -6,8 +6,8 @@ class Numeric
# 100.37.to_money => #<Money @cents=10037>
# require 'bigdecimal'
# BigDecimal.new('100').to_money => #<Money @cents=10000>
- def to_money
- Money.new((self * 100).to_int)
+ def to_money(currency = Money.default_currency)
+ Money.new((self * 100).to_int, currency)
end
end
View
5 test/core_extensions_spec.rb
@@ -17,6 +17,11 @@
money.cents.should == 1234_00
money.currency.should == Money.default_currency
end
+
+ specify "Numeric#to_money accepts optional currency" do
+ 1234.to_money('USD').should == Money.new(123400, 'USD')
+ 1234.to_money('EUR').should == Money.new(123400, 'EUR')
+ end
specify "String#to_money works" do
"20.15".to_money.should == Money.new(20_15)

0 comments on commit bad6f51

Please sign in to comment.
Something went wrong with that request. Please try again.