Did you create variable called "symbols"?


#1



https://www.codecademy.com/courses/ruby-beginner-en-Qn7Qw/1/4?curriculum_id=5059f8619189a5000201fbcb#


Says I didn't create variable called "symbols" but it's clearly there .... what can I do ?


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

# Add your code below!
symbols = []
strings.each do |strings.to_sym|
    strings.push(symbols)
end
end
print symbols

Well I updated the code but still getting that error about missing variable.

updated code:

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

symbols = []
strings.each do |strings.to_sym|
symbols.push(strings)
end
end
print symbols


#2

@markiscoding,
-1
You are using 1 end to many...
With a do ... end you encapsulate a so-called code-block

string.each do |string|
   symbols.push( string.to_sym )
end

-2
With to_sym a =string= is changed to a symbol, therewith the =string= cannot be changed ( is immutable )

http://stackoverflow.com/questions/11447537/using-ruby-symbols
http://stackoverflow.com/questions/16621073/when-to-use-symbols-instead-of-strings-in-ruby
From
http://docs.ruby-lang.org/en/2.2.0/String.html

to_sym → symbol

Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See Symbol#id2name.

"Koala".intern         #=> :Koala
s = 'cat'.to_sym       #=> :cat
s == :cat              #=> true
s = '@cat'.to_sym      #=> :@cat
s == :@cat             #=> true

This can also be used to create symbols that cannot be represented using the :xxx notation