ruby-deepclone
ruby-deepclone copied to clipboard
TypeError (can't copy BigDecimal)
Hi! I need to make a depth copy of objects with BigDecimal values. When a try, I get this error. TypeError (can't copy BigDecimal)
Thanks.
Ok, in fact there are some classes in Ruby which are no cloneable. We catched most of them but probably missed the BigDecimal class. Should be a fairly easy one to fix.
Rodolfo Spalenza [email protected] schrieb:
Hi! I need to make a depth copy of objects with BigDecimal values. When a try, I get this error. TypeError (can't copy BigDecimal)
Thanks.
— Reply to this email directly or view it on GitHub.
Uhh, not that simple since BigDecimal is part of the stdlib and not core. Will have a look on it 2moro.
Hi @balmma, why you can't include stdlib? Thanks.
Well, it's not that simple in a C extension. Most probably the best way would be to catch the exception and use the original value. But I need to do some work to get this running.
Problem fixed. I added a check to not clone Numeric and it's descendants at all (just take the same object). Created GEM version 0.5.0.
Hi @balmma, It keep a problem. I try this:
require "bigdecimal"
require "deep_clone"
big_decimal = BigDecimal.new(1)
new_big_decimal = DeepClone.clone big_decimal
And return this:
TypeError: can't copy BigDecimal
from (irb):5:in `initialize_copy'
from (irb):5:in `initialize_clone'
from (irb):5:in `clone'
from (irb):5
Does it work in the newest version? Btw. which Ruby version are you using?
ruby 2.0.0p353 its working fine but with 1.9.3p374 I get a same error (both with RVM). I'm using 0.6.0 gem version (the rubygems version).