class Hash

Public Instance Methods

delete!(key) click to toggle source

When deleting a value from a hash, return the remaining hash, instead of the deleted value

# File lib/finishing_moves/hash.rb, line 4
def delete!(key)
  self.delete(key)
  return self
end
delete_each(*hash_keys) click to toggle source

Delete all records according to the keys passed in as an array, and return a hash of deleted entries. Silently ignores any keys which are not found.

# File lib/finishing_moves/hash.rb, line 11
def delete_each(*hash_keys)
  deleted_entries = {}
  hash_keys.each do |hash_key|
    value = self.delete(hash_key)
    deleted_entries[hash_key] = value unless value.nil?
  end
  return deleted_entries unless deleted_entries.empty?
  nil
end
delete_each!(*keys) click to toggle source

Delete all records according to the keys passed in as array, and return the remaining hash.

# File lib/finishing_moves/hash.rb, line 22
def delete_each!(*keys)
  self.delete_each(*keys)
  return self
end
sample() click to toggle source

TODO Replicate ‘sample` method functionality from Array

# File lib/finishing_moves/hash.rb, line 29
def sample
  key = self.keys.sample
  return {:"#{key}" => self[key]}
end