Class: Hash

Inherits:
Object show all
Defined in:
lib/cloudkit.rb

Instance Method Summary collapse

Instance Method Details

#excluding(*keys) ⇒ Object

Return a new Hash, excluding the specified list of keys.



78
79
80
81
82
# File 'lib/cloudkit.rb', line 78

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.



64
65
66
67
# File 'lib/cloudkit.rb', line 64

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’



70
71
72
73
74
75
# File 'lib/cloudkit.rb', line 70

def rekey!(oldkey, newkey)
  if self.has_key? oldkey
    self[newkey] = self.delete(oldkey)
  end
  nil
end