A hash in Ruby is kind of like an array. For example, take an array of different ways to say "hello":
hellos = [ "hello", "hola", "bonjour" ]
We access individual values in the array by number:
hellos = [ "hello", "hola", "bonjour" ]
# Indexes: 0 1 2
puts hellos[0] #=> "hello"
puts hellos[1] #=> "hola"
puts hellos[2] #=> "bonjour"
Rather than access these values by these numbers that have very little meaning, it would be great if we could access those values by a name. It turns out that hashes let us do that!
Here is that same information but in a hash:
hellos = {
:english => "hello",
:spanish => "hola",
:french => "bonjour"
}
puts hellos[:english] #=> "hello"
puts hellos[:spanish] #=> "hola"
puts hellos[:french] #=> "bonjour"