Class: Hash

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

Overview

Hash helpers

Instance Method Summary collapse

Instance Method Details

#deep_freezedescription_of_the_return_value

Freeze all values in a hash

Returns:

  • (description_of_the_return_value)


11
12
13
# File 'lib/doing/hash.rb', line 11

def deep_freeze
  map { |k, v| v.is_a?(Hash) ? v.deep_freeze : v.freeze }.freeze
end

#deep_freeze!Object



15
16
17
# File 'lib/doing/hash.rb', line 15

def deep_freeze!
  replace deep_freeze
end

#stringify_keysObject

Turn all keys into string

Return a copy of the hash where all its keys are strings



22
23
24
# File 'lib/doing/hash.rb', line 22

def stringify_keys
  each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v.is_a?(Hash) ? v.stringify_keys : v }
end

#symbolize_keysObject

Turn all keys into symbols



27
28
29
# File 'lib/doing/hash.rb', line 27

def symbolize_keys
  each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v }
end