Module: HashKeysString

Defined in:
lib/hash-keys.rb

Instance Method Summary collapse

Instance Method Details

#recursive__stringify__keys!Object Also known as: recursive_stringify_keys!



92
93
94
95
96
# File 'lib/hash-keys.rb', line 92

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

#recursive__stringify__symbol__values!Object Also known as: recursive_stringify_symbol_values!



99
100
101
102
103
# File 'lib/hash-keys.rb', line 99

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

#stringify__keysObject Also known as: stringify_keys

Return a new hash with all keys converted to strings.



70
71
72
# File 'lib/hash-keys.rb', line 70

def stringify__keys
  dup.stringify__keys!
end

#stringify__keys!Object Also known as: stringify_keys!

Destructively convert all keys to strings.



76
77
78
79
80
81
# File 'lib/hash-keys.rb', line 76

def stringify__keys!
  keys.each do |key|
    self[key.to_s] = delete(key)
  end
  self
end

#stringify__symbol__values!Object Also known as: stringify_symbol_values!



84
85
86
87
88
89
# File 'lib/hash-keys.rb', line 84

def stringify__symbol__values!
  keys.each do |key|
    self[key] = self[key].to_s if self[key].is_a? Symbol
  end
  self
end