From: Joel VanderWerf Date: 2006-03-06T15:08:20+09:00 Subject: Re: [YAML] Bignum problems Joel VanderWerf wrote: > The problems with Bignums in recent YAMLs have been discussed(*), but > does anyone have a patch that can be loaded in ruby code to get around it? > > This just turned into a minor disaster for me... > > $ ruby -v > ruby 1.8.4 (2005-12-24) [i686-linux] > $ ruby -r yaml -e 'y 1234567890' > --- !ruby/object:Bignum 1234567890 > $ ruby -r yaml -e 'YAML.load 1234567890.to_yaml' > /usr/local/lib/ruby/1.8/yaml.rb:133:in `transfer': allocator undefined > for Bignum (TypeError) > from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load' > from -e:1 > > (*) > http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/4d62fa19fc7f4ffe/2331cd65b83bffe2?q=YAML+Bignum&rnum=1#2331cd65b83bffe2 > Answering my own question, but it's a hack... class Bignum def to_yaml( opts = {} ) super.sub(/!ruby\/object:Bignum /, "") end end s = 1000000000000000.to_yaml puts s p YAML.load(s) OUTPUT: --- 1000000000000000 1000000000000000 -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407