Adding .to_sym when asking for input or when adding to hash?


Code works but I added .to_sym and .to_i to the gets.chomp call. Noticed in the example code it's added to movies[title.to_sym] when adding the movie to the hash. I'm wondering if there's an advantage of doing it one way over the other? Does it tax the system less to only convert when adding to the hash? Would make sense since it could jump to the else statement without doing any conversions.

when "add"
  puts "What movie do you want to add?"
  title = gets.chomp.to_sym
      puts "What rating do you want to give it? (from 1 - 4)"
      rating = gets.chomp.to_i
      movies[title] = rating
      puts "Your movie was added!"
      puts "This movie already exists in the database!"


Since you're using the input immediately after reading it, those descriptions both describe the same moment in time, there is no difference


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