我在Ruby中真的很新。
所以我确实在循环中创建了一个菜单,将我发送到" start.menu_one"但是我可以在" def menu_one"中进行另一个循环。这可以把我送到" def menu_three"
问题是我无法运行代码?你们中的任何人都知道问题是什么,因为我无法找到它。
file = File.new(".txt", "a")
class Start
def menu_one
while (select !=2)
puts "Press 1 to make a new test"
puts "Press 2 to search after test results"
if (select == 1)
start.menu_three
break
elsif (select == 2) # its here the problem is?
end
def menu_two
puts "Press 1 to see the overview of the tests"
end
end
def menu_three
puts "hej"
end
end
start = Start.new
require 'io/console'
select = 0
puts "Welcome to the multiple choice test"
while (select !=3)
puts "Press 1 to login as admin"
puts "\n"
puts "Press 2 to login as student"
puts "\n"
puts "Press 3 to exit "
puts "\n"
select = STDIN.getch.to_i
if (select == 1)
start.menu_one
break
elsif (select == 2)
start.menu_two
break
elsif (select == 3)
puts "You have now exited the program"
abort
end
end
end
答案 0 :(得分:0)
class Start
def menu_one
while (select !=2)
puts "Press 1 to make a new test"
puts "Press 2 to search after test results"
if (select == 1)
start.menu_three
break
elsif (select == 2) # its here the problem is?
end
def menu_two
puts "Press 1 to see the overview of the tests"
end
end
def menu_three
puts "hej"
end
end
start = Start.new
require 'io/console'
select = 0
puts "Welcome to the multiple choice test"
while (select !=3)
puts "Press 1 to login as admin"
puts "\n"
puts "Press 2 to login as student"
puts "\n"
puts "Press 3 to exit "
puts "\n"
select = STDIN.getch.to_i
if (select == 1)
start.menu_one
break
elsif (select == 2)
start.menu_two
break
elsif (select == 3)
puts "You have now exited the program"
abort
end
end
end