Method: Hash#update_values
- Defined in:
- lib/core/facets/hash/update_values.rb
#update_values ⇒ Object
Iterate over hash updating just the values.
h = {:a=>1, :b=>2}
h.update_values{ |v| v + 1 }
h #=> { :a=>2, :b=>3 }
CREDIT: Trans
11 12 13 14 15 16 17 |
# File 'lib/core/facets/hash/update_values.rb', line 11 def update_values #:yield: if block_given? each{ |k,v| store(k, yield(v)) } else to_enum(:update_values) end end |