Handy Ruby Hash Methods

Different types of Hash keys:

# String Keys
{ "a" => 1, "b" => 2, "c" => 3 }

# Integer Keys 
{ 1 => "a", 2 => "b", 3 => "c"

# Symbol Keys
{ :a => 1, :b => 2, :c => 3 } #(Hashrocket notation) 
{ a: 1, b: 2, c: 3 }

# Array Keys
{ ['a'] => 1, ['b'] => 2, ['c'] => 3

# Hash Keys 
{ { :a => 1 } => 2, { :b => 2 } => 3

each

irb> { a: 1, b: 2, c: 3 }.each do |pair|
  puts "#{pair.first} #{pair.last}"
end
a 1
b 2
c 3
=> {:a=>1, :b=>2, :c=>3}

irb> { a: 1, b: 2, c: 3 }.each do |key, value|
  puts "#{key} #{value}"
end
a 1
b 2
c 3
=> {:a=>1, :b=>2, :c=>3}

each_key/each_value

irb> { a: 1, b: 2, c: 3 }.each_key do |key|
  puts key
end
a
c
=> {:a=>1, :b=>2, :c=>3}

irb> { a: 1, b: 2, c: 3 }.each_value do |value|
  puts value
end
1
2 
3
=> {:a=>1, :b=>2, :c=>3}

keys/ values