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:
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}