Ruby - Hash Hashes

Introduction

Ruby Hashes are maps, dictionaries.

Objects within a hash are given a key that points to them.

Inside hashes, there's no guaranteed order.

Here's a basic hash with two entries:

Demo

h = { 'A' => 'a', 'B' => 'b' }

The variable storing the hash is h, and it contains two entries, as you can prove:

puts h.size # 2 

You use square brackets to reference the element. For example:

puts dictionary['A'] 

You can change values in hash:

h['A'] = "aa" 
puts h['A'] 

Hash keys and values can be objects of any type.

Related Topics