Class: DeepStruct::Hash
- Inherits:
-
Hash
- Object
- Hash
- DeepStruct::Hash
show all
- Defined in:
- lib/deep_struct/hash.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Hash
Returns a new instance of Hash.
3
4
5
6
7
|
# File 'lib/deep_struct/hash.rb', line 3
def initialize(hash)
hash.each do |k, v|
self[k.to_sym] = v
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
16
17
18
|
# File 'lib/deep_struct/hash.rb', line 16
def method_missing(key, *args, &block)
self[key]
end
|
Instance Method Details
#[](key) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/deep_struct/hash.rb', line 9
def [](key)
v = super(key)
return DeepStruct::Hash.new(v) if v.is_a?(::Hash)
return DeepStruct::Array.new(v) if v.is_a?(::Array)
return v
end
|
#responds_to?(method) ⇒ Boolean
20
21
22
|
# File 'lib/deep_struct/hash.rb', line 20
def responds_to?(method)
self[method]
end
|