语法错误,意外的keyword_when,期待$ ruby​​代码,codecademy,电影之夜6/10

时间:2015-05-30 07:10:47

标签: ruby-on-rails ruby

我在codecademy.com上练习ruby,我收到一个奇怪的错误,但是当我看到代码时,它对我来说是正确的。 以下是我的代码,(您还可以在CodePad

查看代码及其输出
null

这是我收到的错误消息,

movies = {
    'Janwar' =>  4,
    'Tum Bin' =>  3,
    'PK' => 3
}

puts "Select your favorite movie"
puts "type \"add\" to add a movie to the list"
puts "type \"delete\" to delete a movie"
puts "type \"display\" to list the movies"

choice = gets.chomp

case choice
when "add"
    puts "Please say the movie title"
    title = gets.chomp
    puts "What is the rating of the movie"
    rating = gets.
    if  movies[title.to_sym].nil? == true
        movies[title.to_sym] = rating.to_i
    else
        puts "the thing you wanna add is already there"
    end
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!df"
end

有人请在CodePad运行此代码并查看错误是什么?

先谢谢你!

1 个答案:

答案 0 :(得分:1)

这里你错过了一个方法:

 rating = gets. #<<

您可能想要的是rating = gets.chomp