Class: Hash
Instance Method Summary collapse
-
#delete!(key) ⇒ Object
When deleting a value from a hash, return the remaining hash, instead of the deleted value.
-
#delete_each(*hash_keys) ⇒ Object
Delete all records according to the keys passed in as an array, and return a hash of deleted entries.
-
#delete_each!(*keys) ⇒ Object
Delete all records according to the keys passed in as array, and return the remaining hash.
-
#sample ⇒ Object
TODO Replicate ‘sample` method functionality from Array.
Instance Method Details
#delete!(key) ⇒ Object
When deleting a value from a hash, return the remaining hash, instead of the deleted value
4 5 6 7 |
# File 'lib/finishing_moves/hash.rb', line 4 def delete!(key) self.delete(key) return self end |
#delete_each(*hash_keys) ⇒ Object
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.
11 12 13 14 15 16 17 18 19 |
# 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) ⇒ Object
Delete all records according to the keys passed in as array, and return the remaining hash.
22 23 24 25 |
# File 'lib/finishing_moves/hash.rb', line 22 def delete_each!(*keys) self.delete_each(*keys) return self end |
#sample ⇒ Object
TODO Replicate ‘sample` method functionality from Array
29 30 31 32 |
# File 'lib/finishing_moves/hash.rb', line 29 def sample key = self.keys.sample return {:"#{key}" => self[key]} end |