summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb17
-rw-r--r--test/bigdecimal/test_bigdecimal_util.rb5
3 files changed, 31 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ae33e360f9..0e285f88e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Jul 27 00:45:00 2011 Kenta Murata <mrkn@mrkn.jp>
+
+ * ext/bigdecimal/lib/bigdecimal/util.rb (Integer#to_d): added
+ for symmetry to BigDecimal() function with an Integer.
+ fixes #5098. [ruby-dev:44210]
+
+ * test/bigdecimal/test_bigdecimal_util.rb: add test for the above
+ change.
+
Wed Jul 27 00:30:00 2011 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/lib/bigdecimal/util.rb (BigDecimal#to_d): added
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index 6860cfd702..1ec39a30ee 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -1,3 +1,20 @@
+class Integer < Numeric
+ # call-seq:
+ # int.to_d -> bigdecimal
+ #
+ # Convert +int+ to a BigDecimal and return it.
+ #
+ # require 'bigdecimal'
+ # require 'bigdecimal/util'
+ #
+ # 42.to_d
+ # # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
+ #
+ def to_d
+ BigDecimal(self)
+ end
+end
+
class Float < Numeric
# call-seq:
# flt.to_d -> bigdecimal
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb
index c4483715ea..5f03b734cf 100644
--- a/test/bigdecimal/test_bigdecimal_util.rb
+++ b/test/bigdecimal/test_bigdecimal_util.rb
@@ -7,4 +7,9 @@ class TestBigDecimalUtil < Test::Unit::TestCase
x = BigDecimal(1)
assert_same(x, x.to_d)
end
+
+ def test_Integer_to_d
+ assert_equal(BigDecimal(1), 1.to_d)
+ assert_equal(BigDecimal(2<<100), (2<<100).to_d)
+ end
end