Class: HashStruct

Inherits:
Hash
  • Object
show all
Defined in:
lib/hash_struct.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashStruct

Returns a new instance of HashStruct.



2
3
4
5
6
7
# File 'lib/hash_struct.rb', line 2

def initialize hash
  merge! hash
    keys.each { |key|
      eval %{ def self.#{key}; self[:#{key}] end }
    }
end

Class Method Details

.[](hash) ⇒ Object



9
10
11
# File 'lib/hash_struct.rb', line 9

def self.[] hash
  new Hash[hash]
end

Instance Method Details

#merge(*args) ⇒ Object



13
14
15
# File 'lib/hash_struct.rb', line 13

def merge *args
  HashStruct.new(super(*args))
end