Class: Rundeck::ObjectifiedHash
- Inherits:
-
Object
- Object
- Rundeck::ObjectifiedHash
- Defined in:
- lib/rundeck/objectified_hash.rb
Overview
Converts hashes to objects.
Instance Method Summary collapse
-
#initialize(hash) ⇒ ObjectifiedHash
constructor
Creates a new ObjectifiedHash object.
-
#method_missing(key) ⇒ Object
Respond if the requested method is a key in the data hash.
-
#respond_to?(method) ⇒ Boolean
Overload the parent method so this properly returns whether the instance of this object responds to the given method.
-
#to_hash ⇒ Hash
(also: #to_h)
Return the original hash object.
Constructor Details
#initialize(hash) ⇒ ObjectifiedHash
Creates a new ObjectifiedHash object.
5 6 7 8 9 10 11 12 |
# File 'lib/rundeck/objectified_hash.rb', line 5 def initialize(hash) @hash = hash @data = hash.each_with_object({}) do |(key, value), data| value = ObjectifiedHash.new(value) if value.is_a? Hash data[key.to_s.downcase] = value data end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
Respond if the requested method is a key in the data hash.
24 25 26 |
# File 'lib/rundeck/objectified_hash.rb', line 24 def method_missing(key) @data.key?(key.to_s) ? @data[key.to_s] : super end |
Instance Method Details
#respond_to?(method) ⇒ Boolean
Overload the parent method so this properly returns whether the instance of this object responds to the given method.
30 31 32 |
# File 'lib/rundeck/objectified_hash.rb', line 30 def respond_to?(method) @data.key?(method.to_s) || super end |
#to_hash ⇒ Hash Also known as: to_h
Return the original hash object
17 18 19 |
# File 'lib/rundeck/objectified_hash.rb', line 17 def to_hash @hash end |