Class: HashWithIndifferentAccessCustom
- Inherits:
-
Object
- Object
- HashWithIndifferentAccessCustom
- Defined in:
- lib/helpers/hash_with_indifferent_access_custom.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(hash = {}) ⇒ HashWithIndifferentAccessCustom
constructor
A new instance of HashWithIndifferentAccessCustom.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ HashWithIndifferentAccessCustom
Returns a new instance of HashWithIndifferentAccessCustom.
6 7 8 9 10 11 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 6 def initialize(hash = {}) @attributes = {} hash.each { |key, val| self[key] = val } @keys = @attributes.keys @values = @attributes.values end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 4 def attributes @attributes end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
4 5 6 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 4 def keys @keys end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
4 5 6 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 4 def values @values end |
Class Method Details
.[](*arr) ⇒ Object
21 22 23 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 21 def self.[](*arr) new(Hash[*arr]) end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 17 def [](key) @attributes[key.to_sym] end |
#[]=(key, value) ⇒ Object
13 14 15 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 13 def []=(key, value) @attributes[key.to_sym] = value end |
#delete(key) ⇒ Object
25 26 27 28 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 25 def delete(key) @attributes.delete(key) self.class.new(@attributes) end |
#to_json(*_args) ⇒ Object
30 31 32 |
# File 'lib/helpers/hash_with_indifferent_access_custom.rb', line 30 def to_json(*_args) @attributes.to_json end |