Converting Between Symbols and Strings


how i can know if the string have an 's' to convert it to a symbol?

for a weird reason i can pass to next lesson with the code below:
strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

# Add your code below!
symbols = []

strings.each do |key|


Which exercise is that?


I am on that exercise now. They are requesting:

Create a new variable, symbols, and store an empty array in it.

Use .each to iterate over the strings array.

For each s in strings, use .to_sym to convert s to a symbol and use .push to add that new symbol to symbols.

I used the below code and was told it was correct. However the objects still appear as strings rather than symbols when printed to the console.

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

symbols = []

strings.each do |string|



Yes, because each returns the content of the strings array (because it was called on it), and not the symbols array.

If you want to check you can simply add the instruction:


at the end of your code and you'll see that the array will be returned as an array of symbols.


Thanks for the feedback. Yet, the section of the question which asks to convert each s in strings is still unanswered. Help please.


You probably mean each string containing an 's', in which case the include? method does the job.


what would the syntax look like then?


The syntax for the include? method was presented in previous lessons, for example this one:


Great! Thanks. I knew it was somewhere in the course. I just couldn't find it.


Is the "s" mentioned in the question meaning "string" actually? not the "s" letter of each string?


Yea this was a little tricky for me to. They aren't referring to the letter "s" but telling you to assign "s" as the variable for each string. This code works

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

Add your code below!

symbols = []
strings.each do |s|


Why doesn't this code work?

symbols = []
strings.each do |s|


This will only convert s to a symbol but nothing else. It will not modify s.

You can use:

s = s.to_sym

Or better yet, you can simply use to_sym inside your push method.


Yes. "s" means the string in the array.