From 1cc556dc5263bbbe5845b9a7abde9c84dffa7fb0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 10 Jan 2011 15:43:21 -0800 Subject: [PATCH] adding to_d to BigDecimal --- .../lib/active_support/core_ext/big_decimal/conversions.rb | 4 ++++ .../test/core_ext/{bigdecimal.rb => bigdecimal_test.rb} | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) rename activesupport/test/core_ext/{bigdecimal.rb => bigdecimal_test.rb} (83%) diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index f7f03f4d95..3720dbb8b8 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -18,6 +18,10 @@ class BigDecimal end end + def to_d + self + end + DEFAULT_STRING_FORMAT = 'F' def to_formatted_s(format = DEFAULT_STRING_FORMAT) _original_to_s(format) diff --git a/activesupport/test/core_ext/bigdecimal.rb b/activesupport/test/core_ext/bigdecimal_test.rb similarity index 83% rename from activesupport/test/core_ext/bigdecimal.rb rename to activesupport/test/core_ext/bigdecimal_test.rb index 9faad9146f..0272f564de 100644 --- a/activesupport/test/core_ext/bigdecimal.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -7,4 +7,9 @@ class BigDecimalTest < Test::Unit::TestCase assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) end -end \ No newline at end of file + + def test_to_d + bd = BigDecimal.new '10' + assert_equal bd, bd.to_d + end +end