Class: Hash
Direct Known Subclasses
Instance Method Summary collapse
-
#only(*allowed) ⇒ Hash
Create a hash with only key/value pairs in receiver and
allowed
. -
#to_mash ⇒ Mash
Convert to Mash.
Instance Method Details
#only(*allowed) ⇒ Hash
Create a hash with only key/value pairs in receiver and allowed
{ :one => 1, :two => 2, :three => 3 }.only(:one) #=> { :one => 1 }
13 14 15 16 17 |
# File 'lib/dm-core/core_ext/hash.rb', line 13 def only(*allowed) hash = {} allowed.each {|k| hash[k] = self[k] if self.has_key?(k) } hash end |
#to_mash ⇒ Mash
24 25 26 27 28 |
# File 'lib/dm-core/core_ext/hash.rb', line 24 def to_mash hash = Mash.new(self) hash.default = default hash end |