Class: Hash
Instance Method Summary collapse
-
#excluding(*keys) ⇒ Object
Return a new Hash, excluding the specified list of keys.
-
#filter_merge!(other = {}) ⇒ Object
For each key in ‘other’ that has a non-nil value, merge it into the current Hash.
-
#rekey!(oldkey, newkey) ⇒ Object
Change the key ‘oldkey’ to ‘newkey’.
Instance Method Details
#excluding(*keys) ⇒ Object
Return a new Hash, excluding the specified list of keys.
69 70 71 72 73 74 |
# File 'lib/cloudkit.rb', line 69 def excluding(*keys) trimmed = self.dup keys.each{|k| trimmed.delete(k)} trimmed end |
#filter_merge!(other = {}) ⇒ Object
For each key in ‘other’ that has a non-nil value, merge it into the current Hash.
53 54 55 56 57 |
# File 'lib/cloudkit.rb', line 53 def filter_merge!(other={}) other.each_pair{|k,v| self.merge!(k => v) unless v.nil?} self end |
#rekey!(oldkey, newkey) ⇒ Object
Change the key ‘oldkey’ to ‘newkey’
60 61 62 63 64 65 66 |
# File 'lib/cloudkit.rb', line 60 def rekey!(oldkey, newkey) if self.has_key? oldkey self[newkey] = self.delete(oldkey) end nil end |