lib/sugar-high/hash.rb in sugar-high-0.2.8 vs lib/sugar-high/hash.rb in sugar-high-0.2.9
- old
+ new
@@ -1,7 +1,18 @@
+require 'sugar-high/arguments'
+
class Hash
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