tags:

views:

17

answers:

1

I am looking for basic examples of YAML syntax and how to work with it in Ruby. Basically, by looking at the examples, I hope to better understand how to map YAML scalars to object attributes, and whether to use different YAML files or having one YAML file containing multiple objects.

+1  A: 

There is a YAML class in Ruby core which has a short tutorial and a few links.

YAML in Fice Minutes

Serializing and Deserializing objects with Ruby

require "yaml"

test_obj = ["dogs", "cats", "badgers"]

yaml_obj = YAML::dump( test_obj )
                    # -> ---
                         - dogs
                         - cats
                         - badgers
ruby_obj = YAML::load( yaml_obj )
                    # => ["dogs", "cats", "badgers"]
ruby_obj == test_obj
                    # => true
willcodejavaforfood
I have seen this. But if I want the data from the YAML file into e.g. a class Zoo. Is there a way to map dogs, cats onto a attribute pretty_animals ?
poseid
OK I'll update my post
willcodejavaforfood
thanks, the 2nd reference gives the overview i was looking for. BTW reference kwiki seems to be out-of-service (?)
poseid
@poseid - Oh sorry about that, I thought it was just my work blocking that site
willcodejavaforfood