Class: HashWithStructAccess

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

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

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

Class Method Details

.compute_path(path) ⇒ Object

Method stub to be overriden by plugins



16
17
18
# File 'lib/hash_with_struct_access.rb', line 16

def self.compute_path(path)
  path
end