Class: Nestling::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/nestling/hash.rb

Instance Method Summary collapse

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_keysObject

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 |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

#symbolize_keys!Object



21
22
23
# File 'lib/nestling/hash.rb', line 21

def symbolize_keys!
  self.replace(self.symbolize_keys)
end