method
transform_values!
v2_5_5 -
Show latest stable
-
0 notes -
Class: Hash
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6 (0)
- 2_5_5 (38)
- 2_6_3 (0)
- What's this?
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.