From: Robert Klemme Date: 2004-03-15T03:54:34+09:00 Subject: Re: float allocator "Anders Borch" schrieb im Newsbeitrag news:t1Z4c.112164$jf4.6624704@news000.worldonline.dk... > I have been testing ruby 1.8 on my windows box before I dare adopt it on > my linux box. I came across this odd difference: > > In ruby 1.6 I can dup a Float: > > $ ruby -v > ruby 1.6.8 (2002-12-24) [i586-linux-gnu] > $ irb > irb(main):001:0> a = 3.14 > => 3.14 > irb(main):002:0> a.dup > => 3.14 > > In ruby 1.8 I cannot: > > $ ruby -v > ruby 1.8.1 (2003-12-25) [i386-cygwin] > $ irb > irb(main):001:0> a = 3.14 > => 3.14 > irb(main):002:0> a.dup > NoMethodError: allocator undefined for Float > from (irb):2:in `dup' > from (irb):2 > > I did a bit of testing and found out that neither Fixnum, Float or > Bignum can be dup'ed. Is this intentional, and if so then how do I go > about copying the descendents of Numeric? You don't. You gain nothing by dup'ing Integer, Float etc. because these are immutable anyway. You don't gain anything by copying these. OTOH, for a uniform invocation these instance's #dup methods could be defined to return self. Regards robert