ruby-deepclone icon indicating copy to clipboard operation
ruby-deepclone copied to clipboard

TypeError (can't copy BigDecimal)

Open spalenza opened this issue 11 years ago • 8 comments

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.

spalenza avatar Jan 22 '14 13:01 spalenza

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.

balmma avatar Jan 22 '14 19:01 balmma

Uhh, not that simple since BigDecimal is part of the stdlib and not core. Will have a look on it 2moro.

balmma avatar Jan 22 '14 20:01 balmma

Hi @balmma, why you can't include stdlib? Thanks.

spalenza avatar Jan 23 '14 11:01 spalenza

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.

balmma avatar Jan 23 '14 11:01 balmma

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.

balmma avatar Jan 23 '14 13:01 balmma

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

spalenza avatar Jan 23 '14 15:01 spalenza

Does it work in the newest version? Btw. which Ruby version are you using?

balmma avatar Jan 31 '14 06:01 balmma

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).

spalenza avatar Jan 31 '14 11:01 spalenza