undefined local variable or method `movie' for #

movies = { 
    'Kingglaive' => 5
puts "Do you like that movie?"
choice = gets.chomp
case choice
when "add"
  puts "Enter the name of the movie!"
  title = gets.chomp
  puts "What's your rating about it?"
  rating = gets.chomp
  movies[title.intern] = rating.to_i
  if movies[title.intern].nil? 
  puts "#{rating} + movies[title]"
      puts "It already exist!"
when "update"
  puts "What's your movie in mind?"
  title = gets.chomp
  if movie[title].nil?
      puts "You're wrong!"
      puts "What's your new rating then?"
      new_rating = gets.chomp
       movies[title.intern] = rating.to_i
       puts "#{title} has been updated with your new #{rating}"
when "display"
  movies.each do |movie, rating| puts "#{movie}: #{rating}"
when "delete"
  puts "What title do you want to delete?"
  title = gets.chomp.to_sym
    if movie[title.intern.to_s].nil?
      puts "Error!"
      puts "The movie #{title} with a rating of #{rating} has now been deleted!"


The movie hash is not defined. As a side note, you could demonstrate a little more maturity in your puts statement. Try using a response to the user that actually tells them something.

puts "The movie #{movie} does not exist in the database."

Again, movie is not defined.

While intern may be the logical equivalent of .to_sym, it is more common to see it used in an assignment:

new_title = title.intern

Typical in-place conversion uses string.to_sym. But this is not a sticking point, as long as you are sure your approach is working.

On the whole, this is quite messy and convoluted when we look at it.


I wouldn't advise doing it this way. Leave the inputs alone and modify later.

Why convert to a symbol only to convert it back to a string?


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