Sha256: 97feac831a6031e2e5c582bdc6fbb5267c30aaa1fa644b6e1806b050340fdb1e
Contents?: true
Size: 576 Bytes
Versions: 3
Compression:
Stored size: 576 Bytes
Contents
require 'sugar-high/arguments' class Hash # http://www.dweebd.com/ruby/hash-key-rewrite/ def rewrite mapping inject({}) do |rewritten_hash, (original_key, value)| rewritten_hash[mapping.fetch(original_key, original_key)] = value rewritten_hash end end def hash_revert r = Hash.new {|h,k| h[k] = []} each {|k,v| r[v] << k} r end 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 end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sugar-high-0.6.3 | lib/sugar-high/hash.rb |
sugar-high-0.6.2.1 | lib/sugar-high/hash.rb |
sugar-high-0.6.1 | lib/sugar-high/hash.rb |