2012-09-04 97 views
8

有時我會看到使用to_d的代碼。紅寶石文檔甚至指出there is a Float#to_d method。但是,這不是我的紅寶石版本(ruby 1.9.3p263 (2012-08-23 revision 36792)。Float#to_d在哪裏?

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>' 

FloatStringFixnum沒有to_d。這是怎麼回事?

回答