From 2fcb91c74c18680fed4c4067bda6aab60abb5de2 Mon Sep 17 00:00:00 2001 From: mrkn Date: Tue, 26 Jul 2011 15:46:42 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/lib/bigdecimal/util.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ext') 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 + # # => # + # + def to_d + BigDecimal(self) + end +end + class Float < Numeric # call-seq: # flt.to_d -> bigdecimal -- cgit v1.2.3