Error! Error! dealing with spaces in movie titles


The existing hash has a movie title with a space in it, however a symbol with a space will break the code. I replace the space with an underscore then. From {fight club: 5} to {fight_club: 5}

The exercise is to check your existing hash for the new title you want to add. If you enter "fight club" it converts it to a symbol, and then it checks if the movie exists. The movie entered has a space, while the existing movie has an underscore, so the interpreter doesn't catch it. I tested entering "fight_club" and the interpreter catches it and throws the output for my else.

To fully resolve this, you would need to know what "fight club" looked like after being converted to a symbol, because it is not "fight_club"

Otherwise, you would need to check your input for spaces, replace them with underscores, and then check the hash.

That being said, can I get some feedback here? Is there a particular naming convention for keys as symbols, specifically referring to spaces?

Thanks for your time,

movies = {fight_club: 5}

puts "What do you want to do?"
choice = gets.chomp 

case choice
    when "add"
        puts "What is the movie title?"
        title = gets.chomp
        if movies[title.to_sym].nil?
          puts "What's your rating for #{title}?"
          rating = gets.chomp
          movies[title.to_sym] = rating.to_i
          puts "That movie is already here"
    when "update"
        puts "Updated!"
    when "display"
        puts "Movies!"
    when "delete"
        puts "Deleted!"
    puts "Error!"


There's nothing special about space.
Replace them or don't, just do the same everywhere or they obviously won't match.
I'd keep them, because I don't see reason to change the titles.


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