From: ara.t.howard@... Date: 2006-06-03T03:26:20+09:00 Subject: Re: [QUIZ] Hash to OpenStruct (#81) On Sat, 3 Jun 2006, Ruby Quiz wrote: > The three rules of Ruby Quiz: > > 1. Please do not post any solutions or spoiler discussion for this quiz until > 48 hours have passed from the time on this message. > > 2. Support Ruby Quiz by submitting ideas as often as you can: > > http://www.rubyquiz.com/ > > 3. Enjoy! > > Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone > on Ruby Talk follow the discussion. Please reply to the original quiz message, > if you can. > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > by Hans Fugal > > More than a few times I've wished I could get a nice nested OpenStruct out of > YAML data, instead of the more unwieldy nested hashes. It's mostly a matter of > style. It's a straightforward task to convert a nested hash structure into a > nested OpenStruct, but it's the sort of task that you can do a lot of ways, and > I'll bet some of you can come up with more elegant and/or more efficient ways > than I have so far. > > Here's a sample YAML document to get you started: > > --- > foo: 1 > bar: > baz: [1, 2, 3] > quux: 42 > doctors: > - William Hartnell > - Patrick Troughton > - Jon Pertwee > - Tom Baker > - Peter Davison > - Colin Baker > - Sylvester McCoy > - Paul McGann > - Christopher Eccleston > - David Tennant > a: {x: 1, y: 2, z: 3} can we make it more realistic? how bout this a sample data --- foo: 1 bar: baz: [1, 2, 3] quux: 42 doctors: - William Hartnell - Patrick Troughton - Jon Pertwee - Tom Baker - Peter Davison - Colin Baker - Sylvester McCoy - Paul McGann - Christopher Eccleston - David Tennant a: {x: 1, y: 2, z: 3} table: walnut method: linseed oil type: contemporary id: 1234 send: fedex ?? -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama