Skip to content

Instantly share code, notes, and snippets.

@voidius
Created June 5, 2014 16:16
Show Gist options
  • Save voidius/95e89c51c35f8893d16c to your computer and use it in GitHub Desktop.
Save voidius/95e89c51c35f8893d16c to your computer and use it in GitHub Desktop.
DeepStruct
require 'ostruct'
class DeepStruct < OpenStruct
def initialize(hash=nil)
@table = {}
@hash_table = {}
if hash
hash.each do |k,v|
@table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
@hash_table[k.to_sym] = v
new_ostruct_member(k)
end
end
end
def to_h
@hash_table
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment