Class: Niftycloud::ObjectifiedHash
- Inherits:
-
Object
- Object
- Niftycloud::ObjectifiedHash
show all
- Defined in:
- lib/niftycloud/objectified_hash.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ObjectifiedHash.
3
4
5
6
7
8
9
10
|
# File 'lib/niftycloud/objectified_hash.rb', line 3
def initialize(hash)
@hash = hash
@data = hash.inject({}) do |data, (key, value)|
value = ObjectifiedHash.new(value) if value.is_a? Hash
data[key.to_s] = value
data
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
21
22
23
|
# File 'lib/niftycloud/objectified_hash.rb', line 21
def method_missing(key)
@data.key?(key.to_s) ? @data[key.to_s] : nil
end
|
Instance Method Details
#inspect ⇒ Object
17
18
19
|
# File 'lib/niftycloud/objectified_hash.rb', line 17
def inspect
"#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
25
26
27
|
# File 'lib/niftycloud/objectified_hash.rb', line 25
def respond_to_missing?(method_name, include_private = false)
@hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
end
|
#to_hash ⇒ Object
Also known as:
to_h
12
13
14
|
# File 'lib/niftycloud/objectified_hash.rb', line 12
def to_hash
@hash
end
|