From: Joel VanderWerf Date: 2006-03-06T16:07:30+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 > I think this workaround actually works: if RUBY_VERSION == "1.8.4" class Bignum def to_yaml( opts = {} ) YAML::quick_emit( nil, opts ) { |out| out.scalar( nil, to_s, :plain ) } end end end ...that sure beats compiling cvs for several platforms and distributing it to users. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407