Parent

Files

Hash

Public Instance Methods

hash_revert() click to toggle source
# File lib/sugar-high/hash.rb, line 13
def hash_revert
  r = Hash.new {|h,k| h[k] = []}
  each {|k,v| r[v] << k}
  r
end
rewrite(mapping) click to toggle source

www.dweebd.com/ruby/hash-key-rewrite/

# File lib/sugar-high/hash.rb, line 6
def rewrite mapping
  inject({}) do |rewritten_hash, (original_key, value)|
    rewritten_hash[mapping.fetch(original_key, original_key)] = value
    rewritten_hash
  end
end
try_keys(*keys) click to toggle source
# File lib/sugar-high/hash.rb, line 19
def try_keys *keys
  option = last_option keys
  keys.flatten.each do |key|
    return self[key] if self[key]
  end
  return option[:default] if option[:default]
  nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.