Storing information inside YAML

Posted by yuval on Stack Overflow See other posts from Stack Overflow or by yuval
Published on 2010-06-14T00:16:49Z Indexed on 2010/06/14 0:22 UTC
Read the original article Hit count: 680

Filed under:
|
|

I looked through the YAML for ruby documentation and couldn't find an answer.

I have a list of several employees. Each has a name, phone, and email as such:

Employees:
    Name | Phone | Email
    john   111     [email protected]
    joe    123     [email protected]
    joan   321     [email protected]

How would I write the above information in YAML to end up with the following ruby output?

employees = [ {:name => 'john', :phone => '111', :email => '[email protected]'}, {:name => 'joe', :phone => '123', :email => '[email protected]'}, {:name => 'joan', :phone => '321', :email => '[email protected]'} ]

This is how I parse the YAML file:

APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")

Thank you!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby