From: michael greenly Date: 2007-12-31T09:22:21+09:00 Subject: turn nested hashes into nested ostructs ------=_Part_22818_11990033.1199060543491 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline I just thought I'd share this on the off chance anyone would find it useful. It simply turns a nested hash into a nested ostruct. require 'ostruct' class NestedOstruct def self.new(hash) OpenStruct.new(hash.inject({}){|r,p| r[p[0]] = p[1].kind_of?(Hash) ? NestedOstruct.new(p[1]) : p[1]; r }) end end Which allows you to do this... >> a = NestedOstruct.new( :b => { :c => { :d => {:e => 42 } } } ) => #> >> a.b.c.d.e => 42 It's pretty basic but I found the NestedOstruct with YAML::load_file pretty useful today. -- Michael Greenly http://blog.michaelgreenly.com ------=_Part_22818_11990033.1199060543491--