Module: DataMapper::Ext::Hash
- Defined in:
- lib/dm-core/support/ext/hash.rb
Class Method Summary collapse
-
.except(hash, *keys) ⇒ Hash
Returns a hash that includes everything but the given
keys. -
.except!(hash, *keys) ⇒ Hash
Removes the specified
keysfrom the givenhash. -
.only(hash, *keys) ⇒ Hash
Creates a hash with only the specified key/value pairs from
hash. -
.to_mash(hash) ⇒ Mash
Converts the specified
hashto a Mash.
Class Method Details
.except(hash, *keys) ⇒ Hash
Returns a hash that includes everything but the given keys.
33 34 35 |
# File 'lib/dm-core/support/ext/hash.rb', line 33 def self.except(hash, *keys) self.except!(hash.dup, *keys) end |
.except!(hash, *keys) ⇒ Hash
Removes the specified keys from the given hash.
50 51 52 53 |
# File 'lib/dm-core/support/ext/hash.rb', line 50 def self.except!(hash, *keys) keys.each { |key| hash.delete(key) } hash end |
.only(hash, *keys) ⇒ Hash
Creates a hash with only the specified key/value pairs from hash.
15 16 17 18 19 |
# File 'lib/dm-core/support/ext/hash.rb', line 15 def self.only(hash, *keys) h = {} keys.each {|k| h[k] = hash[k] if hash.has_key?(k) } h end |