$ 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?
···
–
dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap
$ 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.
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.
My code is dup’ing objects without knowing what type they are, the great
thing would be to be able to use the same code on my numerics as the
code I can use on all other objects.
OTOH, for a uniform invocation these instance’s #dup methods could be
defined to return self.
This should let me use my code unchanged from ruby 1.6 to 1.8. Thanks
···
Regards
robert
–
dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap