Class: Hash::Accessible
- Inherits:
-
Indifferent
- Object
- Hash
- Normalized
- Indifferent
- Hash::Accessible
- Defined in:
- lib/hash_ext/accessible.rb
Defined Under Namespace
Classes: Array
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Indifferent
Methods inherited from Normalized
#[], #delete, #dig, #fetch, #initialize, #key?, #merge, subclass, #to_h, #update
Methods included from DeepFreezable
Constructor Details
This class inherits a constructor from Hash::Indifferent
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
33 34 35 36 37 38 39 40 |
# File 'lib/hash_ext/accessible.rb', line 33 def method_missing(method, *args, &block) if method.to_s.end_with? '=' key = method[0..-2] self[key] = args[0] else self[method] end end |
Class Method Details
.make_accessible(value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/hash_ext/accessible.rb', line 4 def self.make_accessible(value) if value.kind_of? Hash self.new value elsif value.kind_of? ::Array Accessible::Array.new value else value end end |
Instance Method Details
#[]=(key, value) ⇒ Object
27 28 29 |
# File 'lib/hash_ext/accessible.rb', line 27 def []=(key, value) super key, Accessible.make_accessible(value) end |