| | |
Summary: 2/3/2011
1
Learning Ruby
Ruby Hashes
Hashes
· Hashes introduce a new accessing method similar to arrays
but indexing is by arbitrary keys of any type.
· Not magic Implemented as hash tables (like you learned
about in data structures)
· Unlike arrays, which associate object references with
numbered indices, hashes associate object references with
names/keys
· aka: "associative arrays", "maps" and "dictionaries"
· Hash entries are referred to as "key/value" or "name/value"· Hash entries are referred to as key/value or name/value
pairs
2/3/2011
2
Playing with hashes
favorites = {"class"=> "compilers",
"color" => "blue",
|