From: why the lucky stiff Date: 2006-05-02T01:49:23+09:00 Subject: Re: YAML in limbo? Ohad Lutzky wrote: >This was done with the following code: > > class IPAddr > def to_yaml_type > "!ruby/ipaddr" > end > def to_yaml( opts = {} ) > YAML::quick_emit(self.object_id, opts) { |out| > out << "#{to_yaml_type} " > self.to_s.to_yaml(:Emitter => out) > } > end > end > > YAML.add_ruby_type(/^ipaddr/) { |type, val| > IPAddr.new(val) > } > >This works just fine in Ruby 1.8.3 (Syck 0.45), but b0rks completely in >1.8.4 (Syck 0.6). The +out+ stream no longer has a << operator, and >there is a pretty obvious error in the add_ruby_type method, which seems >to be unused. > > Here's how you do it these days: class IPAddr yaml_as "tag:ruby.yaml.org,2002:ipaddr" def to_yaml(opts = {}) YAML::quick_emit(object_id, opts) do |out| out.scalar(taguri, self.value, :plain) end end end I started doing RDoc for everything. I keep forgetting to wrap it up. _why