class Hash
Public Instance Methods
dig(*path)
click to toggle source
Example usage:
@hash.dig(:k1) # same as @hash[:k1] @hash.dig(:k1, :k2) # same as @hash[:k1] && @hash[:k1][:k2] @hash.dig(:k1, :k2, k3) # same as @hash[:k1] && @hash[:k1][:k2] && @hash[:k1][:k2][:k3]
# File lib/postageapp/utils.rb, line 8 def dig(*path) path.inject(self) do |location, key| location.respond_to?(:keys) ? location[key] : nil end end
recursive_stringify_keys!()
click to toggle source
Destructively convert all keys to strings.
# File lib/postageapp/utils.rb, line 17 def recursive_stringify_keys! keys.each do |key| value = delete(key) self[key.to_s] = case (value) when Hash value.recursive_stringify_keys! else value end end self end