我正在尝试运行这样的代码:
class Run_Fiction_Generator < Fiction_Generator
def generate_story
puts "Title: \"#{generator.title} #{generator.random_date}\""
puts "---------"
puts generator.story
end
end
prompt = '>'
puts "Hello Welcome to Fiction Generator"
puts "First a little about me: "
puts ""
generator = Run_Fiction_Generator.new
puts "This amazing Fiction Generator was created by: #{generator.created_by}"
puts "He's a student with ID number: #{generator.student_id} "
puts ""
puts "Okay now your story! Enter '1' if you want to generate a story now, or '2' if you don't want to"
print prompt
answer = gets.chomp
if answer == "1"
generate_story
else
puts "It was nice meeting you, catch ya later!"
end
但是语句generator_story
中的方法不断抛出这个错误:if
main:Object (NameError) 的未定义局部变量或方法“generate_story”
我的印象是我已经在我的代码中定义了该方法。谁能告诉我哪里出错了?