Hash to deep object with ruby
May 22, 2012
This is a migration from my old blog post which sadly I have to take
down.
I find that I need this quite often, say if I have a hash like this:
1 | hash = { |
and I want to access the hash like this:
1 | obj.level1.level2 # => 'level 2' |
so I use this class (taken form here to get what I want.
1 | require 'ostruct' |
and I use it like this:
1 | deepobject = DeepObject.new(hash) |