Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/casual_support/hash/putbang.rb,
lib/casual_support/hash/displace.rb
Instance Method Summary collapse
-
#displace(key, value) ⇒ Hash
Associates
key
withvalue
, and returnskey
‘s previously associated value. -
#put!(key, value) ⇒ Hash
Associates
key
withvalue
.
Instance Method Details
#displace(key, value) ⇒ Hash
Associates key
with value
, and returns key
‘s previously associated value. If key
had no previously associated value, returns Hash#default.
20 21 22 23 24 |
# File 'lib/casual_support/hash/displace.rb', line 20 def displace(key, value) old_value = self[key] self[key] = value old_value end |
#put!(key, value) ⇒ Hash
Associates key
with value
. Similar to Hash#[]=, but returns the Hash instead of the value. Faster than Hash#merge! for single updates in a loop.
15 16 17 18 |
# File 'lib/casual_support/hash/putbang.rb', line 15 def put!(key, value) self[key] = value self end |