Learn
Hashes and Symbols
Converting Between Symbols and Strings
Converting between strings and symbols is a snap.
:sasquatch.to_s # ==> "sasquatch" "sasquatch".to_sym # ==> :sasquatch
The .to_s
and .to_sym
methods are what you’re looking for!
Instructions
1.
We have an array of strings we’d like to later use as hash keys, but we’d rather they be symbols.
- Create a new variable,
symbols
, and store an empty array in it. - Use
.each
to iterate over thestrings
array. - For each
s
instrings
, use.to_sym
to converts
to a symbol and use.push
to add that new symbol tosymbols
. - Print the
symbols
array.
Check the hint for a refresher on .each
and .push
.