有时我看到代码使用to_d
. ruby 文档甚至声明有一种Float#to_d
方法。但是,它不在我的 ruby ( ruby 1.9.3p263 (2012-08-23 revision 36792
) 版本中。
1.9.3p263 :001 > "0.0".to_d
NoMethodError: undefined method `to_d' for "0.0":String
from (irb):1
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
1.9.3p263 :002 > 0.0.to_d
NoMethodError: undefined method `to_d' for 0.0:Float
from (irb):2
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
1.9.3p263 :003 > 0.to_d
NoMethodError: undefined method `to_d' for 0:Fixnum
from (irb):3
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
没有to_d
,或。Float
_ 这是怎么回事?String
Fixnum