The key


#1

Why could we use these symbols a, s en the word key as a key?

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

strings.each do |s|
symbols.push(s.to_sym)
end

This also works.

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

strings.each do |key|
symbols.push(key.to_sym)
end

And actually we do not really need to convert strings to symbols. As long as the string is short.


#2

I don't understand your question.

It's an array here, not a hash, we don't use any key.


#3

You are right for now but for later on?


#4

What about later on?

s and key in your examples are not used as keys, they are used as variables (variables which don't represent keys either, they represent values).


#5

Ok thanks. So it is only the array of strings we'd like to later use as hash keys.


#6

We could, but then we would need a hash, not an array.