Https://discuss.codecademy.com/c/ruby/hashes-and-symbols/


#1

why the to_sym dosent work in the other ruby ide?? can anyone help me.

colors = {“red” => 1, “green” => 2, “blue” => 3 }

symbols = []

colors.each do |cnvrt|
cnvrt = cnvrt.to_sym
symbols.push(cnvrt)
end
puts symbols

it gives error: undefined method `to_sym’ for [“red”, 1]:Array (NoMethodError)


#2

The parser does not recognize non-standard quotes. Change your, 's to "'s.

Aside

When choosing variable names, write what the object IS, not what it DOES or has happen to it.

  # plural         singular
  #   |               |
    colors.each do |color|
        color = color.to_sym
        symbols.push(color)
    end

#3

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