我对ruby还是很陌生,我正在创建一个CLI应用程序,但是red_meat出现了未定义的方法错误,我快要生气了。如果已经定义了该方法,或者我认为该方法,我将如何定义它?
def menu
puts "Are you interested in finding some delicious recipes?"
puts ""
puts "Enter yes or no"
case (gets.chomp.downcase)
when 'no'
puts "Aww you missed out on some yummy meals. Thank you for dropping by"
when 'yes'
puts "Great! Enter one of the following options (Red meat, Poultry, Seafood or Vegetarian)"
#case (gets.chomp.downcase)
input = gets.strip.downcase
if input = "red meat"
red_meat
end
else
puts "I'm sorry, are you hangry? Please try again"
puts ""
menu
end
def red_meat
puts "red meat recipe 1"
puts "red meat recipe 2"
puts "red meat recipe 3"
puts "red meat recipe 4"
end
错误
ERROR:
cli.rb:22:in `menu': undefined method `red_meat' for #<RecipesCli::CLI:0x00007fd941914228> (NoMethodError)
您需要先定义您的方法,以后才能调用它。 menu
方法的内部或外部。
如从代码的缩进中看到的,read_meat
的方法定义嵌套在menu
的方法定义的inside