Zest.

Ruby: Hash iteration

A short, tested Ruby example for hash iteration. Copy it and adjust the names and paths for your project.

Ruby
h = { "a" => 1, "b" => 2 }
h.each { |key, value| puts "#{key} #{value}" }
h.map { |k, v| [k, v * 2] }.to_h

Find it in Zest

Search for “ruby hash iteration” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Ruby examples

All Ruby examples