【发布时间】:2014-01-12 07:33:03
【问题描述】:
我不断收到以下错误消息:
text.rb:2:in `<main>': undefined method `choices' for main:Object (NoMethodError)
但我似乎无法理解为什么我的方法是“未定义的”:
puts "Select [1] [2] [3] or [q] to quit"; users_choice = gets.chomp
choices(users_choice)
def choices (choice)
while choice != 'q'
case choice
when '1'
puts "you chose one!"
when '2'
puts "you chose two!"
when '3'
puts "you chose three!"
end
end
end
【问题讨论】:
-
你在调用它之后定义方法选择
-
对于高级语言,Ruby 应该能够允许前向声明。 Objective-C 允许这样做。
标签: ruby nomethoderror