Hash Methods
select, map, transform_values, merge, sort_by, to_a and each_with_object.
Example
h = { a: 1, b: 2, c: 3 }
p h.select { |k, v| v > 1 }, h.transform_values { |v| v * 10 }
p h.merge({ d: 4 }), h.sum { |k, v| v }, h.min_by { |k, v| v }Result
{:b=>2, :c=>3}
{:a=>10, :b=>20, :c=>30}
{:a=>1, :b=>2, :c=>3, :d=>4}
6
[:a, 1]Exercise
Join hashes.
h.(other)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.