Sha256: 4bdc0d3b6d928160d1b84e0c520b83a7eb94c80fb406d89c27e7ac02c019853b
Contents?: true
Size: 742 Bytes
Versions: 14
Compression:
Stored size: 742 Bytes
Contents
# frozen_string_literal: true module Doing # Hash helpers class ::Hash ## ## Freeze all values in a hash ## ## @return { description_of_the_return_value } ## def deep_freeze map { |k, v| v.is_a?(Hash) ? v.deep_freeze : v.freeze }.freeze end def deep_freeze! replace deep_freeze end # Turn all keys into string # # Return a copy of the hash where all its keys are strings def stringify_keys each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v.is_a?(Hash) ? v.stringify_keys : v } end # Turn all keys into symbols def symbolize_keys each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v } end end end
Version data entries
14 entries across 14 versions & 1 rubygems