Forum: Ruby Beginner question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
41c176e2a1f2803b58ffecf9602670f2?d=identicon&s=25 Mei C. (hachen)
on 2014-02-25 04:16
Hi All,
I'm taking programming lessons on Code academy, and I am stuck on the
symbols lesson.
The instructions say :

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 array, symbols.
Use .each to iterate over the strings array and convert each string to a
symbol, adding those symbols to symbols.

They give you :

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

# Add your code below!

Could someone please help me and explain to me why the code is written
the way it is?

Much thanks!
Sam Duncan (Guest)
on 2014-02-25 04:59
(Received via mailing list)
So you want to take:

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

... and create from it:

symbols = [:HTML, :CSS, :JavaScript, :Python, :Ruby]

The Array#each method [1] allows you to do something with each member of
strings, and the String#to_sym [2] method allows you to create a symbol
from a string. So roughly:

make a new array called symbols
for each entry in strings, create a corresponding symbol, and put it in
your new symbols array.

Hope that helps!


Andrew Kelley (Guest)
on 2014-02-25 05:24
(Received via mailing list)
Just wanted to thank everyone who replies to these emails. I learned
Ruby via forums and email lists, so I greatly appreciate your

Best Regards,
This topic is locked and can not be replied to.