What is wrong here

Hello,

I have to make a sort of database for movies.

I have this :

movies = { harry_potter: 8}
puts "Wat wil u doen : "
choice = gets.chomp
case choice
when “add”
puts “welke film wilt u toevoegen”
title = gets.chomp
puts “welke rating krijgt deze film”
rating = gets.chomp
if movies[title.to_sym].nil?
movies[title.to_sym] = rating.to_i
puts “Deze film is toegevoegd”
else
puts “Deze flim is al toegevoegd”
end
when “update”
puts “Updated!”
when “display”
puts “Movies!”
when “delete”
puts “Deleted!”
else
puts “Error!”
end

but when I try to add a second time a movie I do not see the message
that the film is al toegevoegd.
What do I do wrong here ?

Roelof

Works for me.

I guess your script runs some kind of infinite loop. Could it be the
case
that the line

movies = { harry_potter: 8}

is inside the loop? If it was the case it could be reinitializing the
hash
table every time.

Xavier N. schreef op 18-11-2014 19:47:
Works for me.

I guess your script runs some kind of infinite loop. Could it be the case that the line

?? ????movies = { harry_potter: 8}

is inside the loop? If it was the case it could be reinitializing the hash table every time.


of course, that is the problem.
The scripts stops and when I do the second time I begin at the starting point.

I have to think about how to solve this one.

Roelof

Do this:

movies = {harry_potter: 8}

loop do
  # your current code
end

and kill the program with Control-C when you want to finish the loop. Of
course, when you run the program again the modifications to the hash are
gone, but you’ll get that first start working which is going to feel
great
:).