What is the Hash datatype in Ruby?

What is the Hash datatype in Ruby? And what is it used for?

Can anyone please explain with an example.

On 30.07.2009 13:44, Prateek A. wrote:

What is the Hash datatype in Ruby? And what is it used for?

Can anyone please explain with an example.

http://www.ruby-doc.org/core/classes/Hash.html

A hash is a collection of pieces of data where you access any selected
item via a key rather than by position (as with eg arrays and lists).

Whether Ruby does this I don’t know but in the olden days hash implied
mapping a key into an address space using a randomizing algorithm which
as far as possible kept items at different addresses. If the hash
created a collision then the item would be moved to some predictable
offset position. It’s therefore a sort of indexing mechanism that
doesn’t require an index.

Arguably it makes sense to use a hash whenever you are dealing with
collections that are not accessed in a particular order.

Am Donnerstag, 30. Jul 2009, 20:44:05 +0900 schrieb Prateek A.:

What is the Hash datatype in Ruby? And what is it used for?

Can anyone please explain with an example.

http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html#UB