Class: OpenStructDeep

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/open_struct_deep.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ OpenStructDeep

Returns a new instance of OpenStructDeep.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/open_struct_deep.rb', line 5

def initialize(hash=nil)
  @table = {}
  if hash
    hash.each_pair do |k, v|
      k = k.to_sym
      v = OpenStructDeep.new v if v.is_a? Hash
      v = v.map { |x| OpenStructDeep.new x } if v.is_a? Array
      @table[k] = v
    end
  end
end