I'm having trouble with underscores and spaces when creating symbols


#1
movies = {
    Alice_in_Wonderland: 4
}

puts "Enter a command!"
choice = gets.chomp

case choice
when "add"
    puts "Which movie?"
    title = gets.chomp
    puts title, title.object_id
    title = title.to_sym
    movies.each { |movie, rating|
        puts movie, movie.object_id
    }
    puts title, title.object_id
    if movies[title].nil?
        puts "Rating of movie?"
        rating = gets.chomp
        rating = rating.to_i
        movies[title] = rating
    else
        puts "This movie has already been rated"
    end
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

When I input text into the console and then convert that text into a symbol, my code so far should add it to the hash with the rating or print the statement "This movie has already been rated". I tested this by inputting "Alice in Wonderland" into the console (without quotes). The symbol :Alice_in_Wonderland is already in the hash with a rating of 4.

The computer doesn't recognize that the symbol version of what I inputted into the console already exists in the hash. I printed the name of the object and the object id of the string version of the title, the symbol version of the key defined in the first lines, and the symbol version of the title that was converted from the string. All three object ids are different, and the two symbol ids are very close to each other. The two symbols should have the same object id, but they don't! This is why my code does not get to the else block. Moreover, the console prints Alice_in_Wonderland for the symbol initially entered in the hash, and prints Alice in Wonderland for the symbol converted from the title inputted into the console.

I was under the impression that:
-symbols could not have spaces
-a string changed to a symbol would have its spaces changed to underscores

I don't want to have to input underscores into the console, as that isn't very user friendly.

So with all of that said, what is going on here?

I know its a text wall but I greatly appreciate the help.


#2

Right on the first point, with exception. The second point is not the case in my limited experience.

We can write symbols in two ways:

Single term without quotes:

Babel: 4,
Crash: 4

When written with quotes, we must use the associative array syntax:

:'Babel' => 4,
:'Crash' => 4

This is also the way to write multiple words with white space

:'Alice in Wonderland' => 4