From: Logan Capaldo Date: 2006-06-05T04:00:28+09:00 Subject: Re: [QUIZ][SOLUTION] Hash to OpenStruct (#81) Here's mine: % cat hash_to_open_struct2.rb require 'yaml' require 'ostruct' class Object def hash_to_ostruct(visited = []) self end end class Array def hash_to_ostruct(visited = []) map { |x| x.hash_to_ostruct(visited) } end end class Hash def hash_to_ostruct(visited = []) os = OpenStruct.new each do |k, v| item = visited.find { |x| x.first.object_id == v.object_id } if item os.send("#{k}=", item.last) else os.send("#{k}=", v.hash_to_ostruct(visited + [ [self, os] ])) end end os end end yaml_source = <