From: Andrew Hite Date: 2007-10-11T05:01:24+09:00 Subject: Re: YAML to Struct Andrew Hite wrote: > Is it possible to take YAML and turn it into a Struct? I want to take > something that looks like this: > > key_1: Value 1 > key_2: Value 2 > > And turn it into an object with accessors...and I'm assuming a Struct > would be my best bet. I'm relatively new to the concepts of YAML and > the Struct class, so I'm banging my head against the wall trying to > figure this out. > > Any ideas? I was able to achieve this using OpenStruct and two lines of code: data = YAML::load(yaml_data).to_hash @item = OpenStruct.new(data) -- Posted via http://www.ruby-forum.com/.