Class: HashWithStructAccess

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

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ HashWithStructAccess

Returns a new instance of HashWithStructAccess.



4
5
6
7
8
9
# File 'lib/hash_with_struct_access.rb', line 4

def initialize(hash = {})
  hash.each_pair do |key, value|
    self[key] = value.kind_of?(Hash) ? self.class.new(value) : value
  end
  self.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



11
12
13
# File 'lib/hash_with_struct_access.rb', line 11

def method_missing(method_name)
  self[method_name] || self[method_name.to_s] || super
end