From: Mark Campbell Date: 2012-04-14T22:19:46+09:00 Subject: Re: Why doesn't Fixnum#to_d exist? --f46d0401f8f712adcf04bda371be Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I totally agree with you, however, as I mentioned in my first post, I am using 1.8.7, which does not have this. In fact, 1.9.2 doesn't have it either: 1.8.7 :001 > require 'bigdecimal' =3D> true 1.8.7 :002 > require 'bigdecimal/util' =3D> true 1.8.7 :003 > 25.to_d NoMethodError: undefined method `to_d' for 25:Fixnum from (irb):3 1.8.7 :004 > mark@mark-desktop ~$ rvm use 1.9.2 Using /home/mark/.rvm/gems/ruby-1.9.2-p290 mark@mark-desktop ~$ irb 1.9.2p290 :001 > require 'bigdecimal' =3D> true 1.9.2p290 :002 > require 'bigdecimal/util' =3D> true 1.9.2p290 :003 > 25.to_d NoMethodError: undefined method `to_d' for 25:Fixnum from (irb):3 from /home/mark/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' 1.9.2p290 :004 > mark@mark-desktop ~$ rvm use 1.9.3 Using /home/mark/.rvm/gems/ruby-1.9.3-p125 mark@mark-desktop ~$ irb 1.9.3p125 :001 > require 'bigdecimal' =3D> true 1.9.3p125 :002 > require 'bigdecimal/util' =3D> true 1.9.3p125 :003 > 25.to_d =3D> # 1.9.3p125 :004 > So, can we add this to stdlib of 1.8.7 and 1.9.2? 2012/4/14 Bartosz Dziewo=C5=84ski > >irb > irb(main):001:0> require 'bigdecimal' > =3D> true > irb(main):002:0> require 'bigdecimal/util' > =3D> true > irb(main):003:0> 25.to_d > =3D> # > > I'm running Ruby 1.9.3 on Windows XP. According to the docs[1], #to_d > is defined for BigDecimal, Float, Rational, String, and Integer (which > is a superclass of Fixnum and Bignum). > > [1] http://www.ruby-doc.org/stdlib-1.9.3/libdoc/bigdecimal/rdoc/index.htm= l > > -- Matma Rex > > --f46d0401f8f712adcf04bda371be Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I totally agree with you, however, as I mentioned in my first post, I am us= ing 1.8.7, which does not have this. In fact, 1.9.2 doesn't have it eit= her:

1.8.7 :001 > require 'bigdecimal'
=C2=A0=3D> true=C2=A0
1.8.7 :002 > require 'bigdec= imal/util'
=C2=A0=3D> true=C2=A0
1.8.7 :003 >= 25.to_d
NoMethodError: undefined method `to_d' for 25:Fixnum=
from (irb):3
1.8.7 :004 > mark@mark-desktop ~$ rvm use 1.9.2
Using /ho= me/mark/.rvm/gems/ruby-1.9.2-p290
mark@mark-desktop ~$ irb
<= div>1.9.2p290 :001 > require 'bigdecimal'
=C2=A0=3D>= ; true=C2=A0
1.9.2p290 :002 > require 'bigdecimal/util'
=C2=A0= =3D> true=C2=A0
1.9.2p290 :003 > 25.to_d
NoMethod= Error: undefined method `to_d' for 25:Fixnum
from (irb):3
from = /home/mark/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
1.9.2p290 :004 >=C2=A0
mark@mark-desktop ~$ rvm use 1.9= .3
Using /home/mark/.rvm/gems/ruby-1.9.3-p125
mark@mark-desktop= ~$ irb
1.9.3p125 :001 > require 'bigdecimal'
=C2=A0=3D> true=C2=A0
1.9.3p125 :002 > require 'bigde= cimal/util'
=C2=A0=3D> true=C2=A0
1.9.3p125 :003 > 25.to_d
=C2=A0=3D> #<BigDecimal:17ff778,'0.25E2',9(36)>=C2=A0
1.9.3p125 :004 >=C2=A0

So, can we add = this to stdlib of 1.8.7 and 1.9.2?=C2=A0

2012/4/14 Bartosz Dziewo=C5=84ski <matma.rex@gmail.com= >
>irb
irb(main):001:0> require 'bigdecimal'
=3D> true
irb(main):002:0> require 'bigdecimal/util'
=3D> true
irb(main):003:0> 25.to_d
=3D> #<BigDecimal:1068060,'0.25E2',9(36)>

I'm running Ruby 1.9.3 on Windows XP. According to the docs[1], #to_d is defined for BigDecimal, Float, Rational, String, and Integer (which
is a superclass of Fixnum and Bignum).

[1] http://www.ruby-doc.org/stdlib-1.9.3/libdoc/b= igdecimal/rdoc/index.html

-- Matma Rex


--f46d0401f8f712adcf04bda371be--