HashSets
Learn what hash sets are and how to use them in Ruby.
We'll cover the following...
Listing all keys in a hash
There is a way in Ruby language to list all the keys in a hash. Here is how this method works:
$ pry
> hh = {}
=> {}
> hh[:red] = 'ff0000'
=> "ff0000"
> hh[:green] = '00ff00'
=> "00ff00"
> hh[:blue] = '0000ff'
=> "0000ff"
> hh.keys
=> [:red, :green, :blue]
We defined a hash and pushed a few key-value pairs in it. Keys are a type of symbol, and values are just strings. These strings (ff0000
, 00ff00
, and 0000ff
) are conventional three-byte representations of the color ...