Error! Error!


#1

Guys, I keep getting this message: undefined method `to' for "random title":String

This is my code:

movies = {
Lebowsky: 5,
Pulp: 5,
Donnie: 5,
Foundamentals: 4

}

puts "Chose and action"
choice = gets.chomp

case choice
when "add"
puts "Type a title"
title = gets.chomp
if movies[title.to.sym].nil?
puts "Please, rate this movie"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else
puts "That's already in our database!"
end

when "update"
puts "Updated"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#2

Did you mean to call a method named to?
If not, search your code for where you do that and change it to what you meant


#3

That was the stupidest mistake ever :slight_smile:


#4

The mistake or not fixing it? We make mistakes, we just gotta find them later, and error messages are there to say what's wrong so we gotta read them.

A good start is usually verifying the problem so you know you're chasing the right thing, and then consider why it shouldn't have happened - because that reason probably says which part of the code isn't doing its job


#6

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