Questions about converting symbols


Exercise: Converting between Symbols and Strings| Many Paths to the same Summit

I opened this topic just to clarify if my understanding of the code below is correct, because i don't want to move to another lesson without it being clear.. Also i have few questions regarding the code.

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

symbols = []

strings.each do |s|

puts symbols[2][2]

symbols.push(s.intern)  # I have two questions regarding this line

1. which is the first to be executed? does ruby convert the s to symbols first and then inserts it inside the 'symbols'?

2. Was the 'symbols' changed from an array to symbol? or it is still an array that have symbols inside?

I checked if it's the case by accessing the index puts symbols[0] returns "HTML"

and when i do this puts symbols[0][1] it returns "H" because i'm accessing the first index [0], and the [1] returns the H, but why is that happening? The structure is confusing me..

Thank you so much to anyone who will answer this question... I'd like to apologize to this bad grammar..


it's looping so it converts each item in the strings array respectively [0,1,2,3...]

Yes and no,

because if you use the ruby method .include? it will return false if you check for an item that's actually in the array however if you print out symbols you will see the item you were searching for,

It sort of becomes as if each word is it's own array like a multidimensional array,

you saying puts symbols[0][1]

is telling Ruby to return this

: H T M L
0 1 2 3 4

//the bold letter


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.