lib/bigdecimal/util.rb in bigdecimal-1.3.5 vs lib/bigdecimal/util.rb in bigdecimal-1.4.0.pre.20181121a
- old
+ new
@@ -3,10 +3,12 @@
#--
# bigdecimal/util extends various native classes to provide the #to_d method,
# and provides BigDecimal#to_d and BigDecimal#to_digits.
#++
+require 'bigdecimal'
+require 'bigdecimal/util.so'
class Integer < Numeric
# call-seq:
# int.to_d -> bigdecimal
#
@@ -40,12 +42,12 @@
# 0.5.to_d # => 0.5e0
# 1.234.to_d(2) # => 0.12e1
#
# See also BigDecimal::new.
#
- def to_d(precision=nil)
- BigDecimal(self, precision || Float::DIG)
+ def to_d(precision=Float::DIG)
+ BigDecimal(self, precision)
end
end
class String
@@ -62,16 +64,9 @@
# "123.45e1".to_d # => 0.12345e4
# "45.67 degrees".to_d # => 0.4567e2
#
# See also BigDecimal::new.
#
- def to_d
- begin
- BigDecimal(self)
- rescue ArgumentError
- BigDecimal(0)
- end
- end
end
class BigDecimal < Numeric
# call-seq: