Hashes

suggest change

Introduction

A Hash is a dictionary-like collection of unique keys and their values. Also called associative arrays, they are similar to Arrays, but where an Array uses integers as its index, a Hash allows you to use any object type. You retrieve or create a new entry in a Hash by referring to its key.

Syntax

Remarks

Hashes in Ruby map keys to values using a hash table.

Any hashable object can be used as keys. However, it’s very common to use a Symbol as it is generally more efficient in several Ruby versions, due to the reduced object allocation.

{ key1: "foo", key2: "baz"  }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents