This post talks about complete tutorials on Hash
What are hashtables and uses in Ruby?
hash is a data structure that stores collection of key and value pairs in computer science, It is similar todictionary in python and hashtable in java. Each key is mapped with corresponding values. The hash in ruby used for storage of key-value pairs, fast loopup of a data, helps developer for wide range of applications.
In Ruby these are declaered with hash class in curly braces with key and value pairs.
employee = { "id" => 11, "name" => "john", "salary" => 5000 }
In this example, the hash table employee has three key-value pairs, where the keys are strings (“id”, “name”, and “salary”), and the corresponding values are 11, john
, and 5000, respectively.
The hash in ruby offers below uses in used wide range of applications
- Fast Lookup data
- Data storage
- Wide range of applications