Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/txcatcher/utils/hash_string_to_sym_keys.rb

Instance Method Summary collapse

Instance Method Details

#keys_to_symObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/txcatcher/utils/hash_string_to_sym_keys.rb', line 12

def keys_to_sym
  symbolized_hash = {} 
  self.each do |k,v|
    if k =~ /\A[a-zA-Z0-9!?_]+\Z/
      symbolized_hash[k.to_sym] = v
    else
      symbolized_hash[k] = v
    end
  end
  symbolized_hash
end

#keys_to_sym!Object

Replace String keys in the current hash with symbol keys



4
5
6
7
8
9
10
# File 'lib/txcatcher/utils/hash_string_to_sym_keys.rb', line 4

def keys_to_sym!
  new_hash = keys_to_sym
  self.clear
  new_hash.each do |k,v|
    self[k] = v
  end
end