HashSets
Explore Ruby hash sets to understand how they store unique elements without associated values. Learn to differentiate hash sets from regular hashes and apply this knowledge to efficiently check if a string contains all alphabet letters, optimizing memory use while iterating over text.
We'll cover the following...
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 ...