Method: Hash#swap!
- Defined in:
- lib/core/facets/hash/swap.rb
#swap!(key1, key2) ⇒ Object
Swap the values of a pair of keys in place.
{:a=>1,:b=>2}.swap!(:a,:b) #=> {:a=>2,:b=>1}
CREDIT: Gavin Sinclair
9 10 11 12 13 14 |
# File 'lib/core/facets/hash/swap.rb', line 9 def swap!(key1, key2) tmp = self[key1] self[key1] = self[key2] self[key2] = tmp self end |