M
michael greenly
[Note: parts of this message were removed to make it a legal post.]
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...
=> 42
It's pretty basic but I found the NestedOstruct with YAML::load_file pretty
useful today.
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...
=> 42
It's pretty basic but I found the NestedOstruct with YAML::load_file pretty
useful today.