Using ! for to_sym and to_i


title.to_sym! and rating.to_i! give an error:
undefined method `to_sym!' for "Fight club":String

case choice
when "add" 
    puts "Movie title: "
    title = gets.chomp
    puts "Rating: "
    rating = gets.chomp
    movies[title] = rating
    puts "Added #{title} with rating of #{rating}"
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
    puts "Error!"


Not every Ruby method has a ! equivalent. The to_i and to_sym methods in Ruby don't have a ! version.

You can see all of the methods available on String in Ruby here.


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