[前][次][番号順一覧][スレッド一覧]

ruby-changes:20629

From: mrkn <ko1@a...>
Date: Wed, 27 Jul 2011 00:46:52 +0900 (JST)
Subject: [ruby-changes:20629] mrkn:r32677 (trunk): * ext/bigdecimal/lib/bigdecimal/util.rb (Integer#to_d): added

mrkn	2011-07-27 00:46:42 +0900 (Wed, 27 Jul 2011)

  New Revision: 32677

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32677

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/lib/bigdecimal/util.rb
    trunk/test/bigdecimal/test_bigdecimal_util.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32676)
+++ ChangeLog	(revision 32677)
@@ -1,3 +1,12 @@
+Wed Jul 27 00:45:00 2011  Kenta Murata  <mrkn@m...>
+
+	* 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@m...>
 
 	* ext/bigdecimal/lib/bigdecimal/util.rb (BigDecimal#to_d): added
Index: ext/bigdecimal/lib/bigdecimal/util.rb
===================================================================
--- ext/bigdecimal/lib/bigdecimal/util.rb	(revision 32676)
+++ ext/bigdecimal/lib/bigdecimal/util.rb	(revision 32677)
@@ -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
Index: test/bigdecimal/test_bigdecimal_util.rb
===================================================================
--- test/bigdecimal/test_bigdecimal_util.rb	(revision 32676)
+++ test/bigdecimal/test_bigdecimal_util.rb	(revision 32677)
@@ -7,4 +7,9 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]