method
transform_values
Ruby latest stable (v2_5_5)
-
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
Returns a new hash with the results of running the block once for every value. 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: "1", b: "2", c: "3" } h.transform_values.with_index {|v, i| "#{v}.#{i}" } #=> { a: "1.0", b: "2.1", c: "3.2" }
If no block is given, an enumerator is returned instead.