Class: IndifferentAccessHash
- Inherits:
-
Object
- Object
- IndifferentAccessHash
- Defined in:
- lib/brightbox-cli/indifferent_access_hash.rb
Overview
A simpler wrapper to allows either String or Symbol keys to be used when accessing attributes since fog applies a change on the top level resulting in a mix of both which has introduced issues.
Instance Method Summary collapse
-
#==(other) ⇒ Object
The result of the comparison.
-
#[](key) ⇒ Object
The value of the key.
-
#[]=(key, value) ⇒ Object
The value of the key.
-
#initialize(hash) ⇒ IndifferentAccessHash
constructor
A new instance of IndifferentAccessHash.
- #method_missing(method, *args, &block) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(hash) ⇒ IndifferentAccessHash
Returns a new instance of IndifferentAccessHash.
5 6 7 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 5 def initialize(hash) @hash = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29 30 31 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 29 def method_missing(method, *args, &block) @hash.send(method, *args, &block) end |
Instance Method Details
#==(other) ⇒ Object
Returns the result of the comparison.
25 26 27 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 25 def ==(other) @hash == (other.is_a?(IndifferentAccessHash) ? other.to_h : other) end |
#[](key) ⇒ Object
Returns the value of the key.
11 12 13 14 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 11 def [](key) value = @hash[key.to_s] || @hash[key.to_sym] wrap(value) end |
#[]=(key, value) ⇒ Object
Returns the value of the key.
19 20 21 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 19 def []=(key, value) @hash[key.to_sym] = value end |
#to_h ⇒ Object
33 34 35 |
# File 'lib/brightbox-cli/indifferent_access_hash.rb', line 33 def to_h @hash end |