diff options
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/jacobian.rb | 3 | ||||
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/util.rb | 30 |
2 files changed, 9 insertions, 24 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/jacobian.rb b/ext/bigdecimal/lib/bigdecimal/jacobian.rb index 84c50248b7..9cad06c09b 100644 --- a/ext/bigdecimal/lib/bigdecimal/jacobian.rb +++ b/ext/bigdecimal/lib/bigdecimal/jacobian.rb @@ -21,9 +21,6 @@ # # fx is f.values(x). # - -require 'bigdecimal' - module Jacobian module_function diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb index 88f490cb45..911fa6fe3a 100644 --- a/ext/bigdecimal/lib/bigdecimal/util.rb +++ b/ext/bigdecimal/lib/bigdecimal/util.rb @@ -5,8 +5,6 @@ # and provides BigDecimal#to_d and BigDecimal#to_digits. #++ -require 'bigdecimal' -require 'bigdecimal/util.so' class Integer < Numeric # call-seq: @@ -44,8 +42,8 @@ class Float < Numeric # # See also BigDecimal::new. # - def to_d(precision=Float::DIG) - BigDecimal(self, precision) + def to_d(precision=nil) + BigDecimal(self, precision || Float::DIG) end end @@ -66,6 +64,13 @@ class String # # See also BigDecimal::new. # + def to_d + begin + BigDecimal(self) + rescue ArgumentError + BigDecimal(0) + end + end end @@ -127,20 +132,3 @@ class Rational < Numeric BigDecimal(self, precision) end end - - -class NilClass - # call-seq: - # nil.to_d -> bigdecimal - # - # Returns nil represented as a BigDecimal. - # - # require 'bigdecimal' - # require 'bigdecimal/util' - # - # nil.to_d # => 0.0 - # - def to_d - BigDecimal(0) - end -end |