I just got the CVS version of Ruby installed and was pleasantly surprised to
see a BigDecimal class. I started playing with it in irb and came up against
some confusion.
The comment at the top of RUBY_HOME/bigdecimal/util.rb says the following:
Float#
to_d … to BigDecimal
Yet the code says it returns a BigFloat
class Float < Numeric
def to_d
BigFloat::new(selt.to_s)
end
end
Also, is this a typo?
class Float < Numeric
def to_d
BigFloat::new(selt.to_s) <— should be self?
end
end
I thought I could use String#to_d as the file comment suggests:
String#
to_d … to BigDecimal
Yet when I do this in irb it gives me an error:
irb(main):002:0> require ‘bigdecimal/util’
=> true
irb(main):003:0> ‘111.333333’.to_d
ArgumentError: wrong number of arguments(1 for 0)
from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:in initialize' from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:innew’
from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:in `to_d’
from (irb):3
User error here on my part?