Class: Nestling::Hash
- Inherits:
-
Hash
- Object
- Hash
- Nestling::Hash
- Defined in:
- lib/nestling/hash.rb
Instance Method Summary collapse
-
#initialize(hash = nil, *args) ⇒ Hash
constructor
A new instance of Hash.
- #method_missing(meth, *args, &block) ⇒ Object
-
#symbolize_keys ⇒ Object
Adapted from ActiveSupport (part of Ruby on Rails) Released under the MIT license.
- #symbolize_keys! ⇒ Object
Constructor Details
#initialize(hash = nil, *args) ⇒ Hash
Returns a new instance of Hash.
3 4 5 6 |
# File 'lib/nestling/hash.rb', line 3 def initialize(hash = nil, *args) self.merge!(hash) if hash super *args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
8 9 10 |
# File 'lib/nestling/hash.rb', line 8 def method_missing(meth, *args, &block) (val = self[meth]) ? val : super(meth, *args, &block) end |
Instance Method Details
#symbolize_keys ⇒ Object
Adapted from ActiveSupport (part of Ruby on Rails) Released under the MIT license
14 15 16 17 18 19 |
# File 'lib/nestling/hash.rb', line 14 def symbolize_keys inject({}) do |, (key, value)| [(key.to_sym rescue key) || key] = value end end |
#symbolize_keys! ⇒ Object
21 22 23 |
# File 'lib/nestling/hash.rb', line 21 def symbolize_keys! self.replace(self.symbolize_keys) end |