Module: HashKeysSymbol

Defined in:
lib/hash-keys.rb

Instance Method Summary collapse

Instance Method Details

#recursive__symbolize__keys!Object Also known as: recursive_symbolize_keys!



126
127
128
129
130
# File 'lib/hash-keys.rb', line 126

def recursive__symbolize__keys!
  symbolize__keys!
  values.select{|v| v.is_a? Hash}.each{|h| h.recursive__symbolize__keys!}
  self
end

#symbolize__keysObject Also known as: symbolize_keys, to_options

Return a new hash with all keys converted to symbols, as long as they respond to to_sym.



110
111
112
# File 'lib/hash-keys.rb', line 110

def symbolize__keys
  dup.symbolize__keys!
end

#symbolize__keys!Object Also known as: symbolize_keys!, to_options!

Destructively convert all keys to symbols, as long as they respond to to_sym.



117
118
119
120
121
122
# File 'lib/hash-keys.rb', line 117

def symbolize__keys!
  keys.each do |key|
    self[(key.to_sym rescue key) || key] = delete(key)
  end
  self
end