Search⌘ K
AI Features

Hash in Ruby

Explore how to create and manipulate hashes in Ruby by defining key-value pairs using symbols and strings. Understand different hash syntaxes, how to access values by keys, and the significance of symbols versus strings as keys in hashes.

We'll cover the following...

Defining hash in Ruby

To define a hash in a Ruby program, we need to use curly brackets. Remember that we use square brackets for arrays:

$ pry
> obj = {}
...
> obj.class
Hash < Object
...