Class: Hash

Inherits:
Object show all
Defined in:
lib/ubiquitously/extensions/core.rb

Instance Method Summary collapse

Instance Method Details

#recursively_symbolize_keys!Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ubiquitously/extensions/core.rb', line 29

def recursively_symbolize_keys!
  self.symbolize_keys!
  self.values.each do |v|
    if v.is_a? Hash
      v.recursively_symbolize_keys!
    elsif v.is_a? Array
      v.recursively_symbolize_keys!
    end
  end
  self
end

#symbolize_keysObject



41
42
43
44
45
46
# File 'lib/ubiquitously/extensions/core.rb', line 41

def symbolize_keys
  inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

#symbolize_keys!Object

Destructively convert all keys to symbols.



49
50
51
# File 'lib/ubiquitously/extensions/core.rb', line 49

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