class Hash

load 'the_role/hash.rb' - UPDATE, BUT NOT RELOAD [for console testing]

Public Instance Methods

deep_reset(default = nil) click to toggle source
# File lib/the_role_api/hash.rb, line 48
def deep_reset(default = nil)
  hash = dup
  hash.each do |key, value|
    hash[key] = hash[key].is_a?(Hash) ? hash[key].deep_reset(default) : default
  end
  hash
end
deep_reset!(default = nil) click to toggle source
# File lib/the_role_api/hash.rb, line 56
def deep_reset!(default = nil)
  replace deep_reset(default)
end
deep_stringify_keys() click to toggle source
# File lib/the_role_api/hash.rb, line 28
def deep_stringify_keys
  deep_transform_keys{ |key| key.to_s }
end
deep_stringify_keys!() click to toggle source
# File lib/the_role_api/hash.rb, line 32
def deep_stringify_keys!
  deep_transform_keys!{ |key| key.to_s }
end
deep_transform_keys() { |key| ... } click to toggle source
# File lib/the_role_api/hash.rb, line 10
def deep_transform_keys(&block)
  result = {}
  each do |key, value|
    result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
  end
  result
end
deep_transform_keys!() { |key| ... } click to toggle source
# File lib/the_role_api/hash.rb, line 18
def deep_transform_keys!(&block)
  keys.each do |key|
    value = delete(key)
    self[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys!(&block) : value
  end
  self
end
underscorify_keys() click to toggle source
# File lib/the_role_api/hash.rb, line 38
def underscorify_keys
  deep_transform_keys{ |key| key.to_slug_param(sep: '_') }
end
underscorify_keys!() click to toggle source
# File lib/the_role_api/hash.rb, line 42
def underscorify_keys!
  replace underscorify_keys
end