[ANN] YAML.rb 0.40 -- Circular references, Emitter enhancements

Aha! A new YAML.rb is out at long last: >

YAML is a structured data format. You may have used Wiki? Well, Wiki is
a powerful alternative to HTML. In many ways, YAML is an alternative to
XML. You can represent almost any Ruby object in YAML.

Some good places to start learning are:

About the new release: >

The new YAML.rb 0.40 now handles references in emitting (including circular
references). This release also introduces numerous enhancements and fixes
to the Emitter class. Thanks to Tom Sawyer for a number of bug reports.

The latest release also adds convenient methods for adding your own custom
to_yaml methods to your classes. For example, if you have an object and
you want to organize its properties in a specific order:

  class MouseMan
    attr_accessor :name, :cape, :length_of_tail
    def to_yaml( opts = {} )
      YAML::quick_emit( self.id, opts ) { |out|
        out.map( "!ruby/object:MouseMan" ) { |map|
          [:name, :cape, :length_of_tail].each { |p|
            map.add( p.id2name, self.send( p ) )
          }
        }
      }
    end
  end 

  mm = MouseMan.new
  mm.name = "Zipper"
  mm.cape = true
  mm.length_of_tail = "1.45 cm"

  puts mm.to_yaml
  # (prints)
  #    --- !ruby/object:MouseMan
  #    name: Zipper
  #    cape: (true)
  #    length_of_tail: 1.45 cm

So, there are basically Emitter#map and Emitter#seq methods for
controlling how you output those constructs.

This document is also valid YAML!: >

Try copying and pasting it into IRB, like:

txt =<<EOY
# .. paste in here ..
EOY
ann = YAML::load( txt )

Then, access the ‘ann’ variable. Should be a Ruby Hash!

YAML.rb is available at http://yaml4r.sf.net/

_why

_why,

Thank you for the cookbook! I like the way you have layed it out with the YAML
then the Ruby - very very nice.


Signed,
Holden Glova

···

On Fri, 30 Aug 2002 05:21, yamlrb@whytheluckystiff.net wrote:

Aha! A new YAML.rb is out at long last: >

YAML is a structured data format. You may have used Wiki? Well, Wiki is
a powerful alternative to HTML. In many ways, YAML is an alternative to
XML. You can represent almost any Ruby object in YAML.

Some good places to start learning are:

Yeah, it works out I guess.

Also, there’s new documentation (work in progress) at [http://yaml4r.sf.net/doc/]
which includes a tutorial and basic reference.

_why

···

Holden Glova (dsafari@paradise.net.nz) wrote:

_why,

Thank you for the cookbook! I like the way you have layed it out with the YAML
then the Ruby - very very nice.