Flowdock
method

transform_values!

Importance_1
v2_5_5 - Show latest stable - 0 notes - Class: Hash
transform_values!() public

Invokes the given block once for each value in hsh, replacing it with the new value returned by the block, and then returns hsh. This method does not change the keys.

h = { a: 1, b: 2, c: 3 }
h.transform_values! {|v| v * v + 1 }  #=> { a: 2, b: 5, c: 10 }
h.transform_values!(&:to_s)           #=> { a: "2", b: "5", c: "10" }
h.transform_values!.with_index {|v, i| "#{v}.#{i}" }
                                      #=> { a: "2.0", b: "5.1", c: "10.2" }

If no block is given, an enumerator is returned instead.

Show source
Register or log in to add new notes.