我想在Ruby中创建一个菜单,以便取决于用户输入的内容,取决于调用的是什么类。然后,在这种情况下,它将返回到“Main”或类“Options”。Ruby中的选项菜单
我希望有人能帮助我。这是我的代码。
module Physics
G = 21
C = 20000
Pi = 3.14
D = 100
end
class Options
puts "Please select 1 for Acceleration and 2 for Energy."
option = gets()
if option == 1
then
puts "AccelCalc" # This is the bit that needs to direct the user to the class AccelCalc
else
puts "EnergyCalc" # This needs to take them to EnergyCalc.
end
end
class AccelCalc
include Physics
puts "Please enter the mass of the object"
M = gets()
puts "The mass of the object is " + M + "."
puts "Please enter the speed of the defined object."
S = gets()
puts "The speed of the object is set at " + S + "."
puts "The acceleration will now be calculated."
puts S.to_i*M.to_i
end
class EnergyCalc
include Physics
puts "This will use the function E=MC^2 to calculate the Energy."
puts "Enter object mass"
M = gets()
puts "The mass is " + M + "."
puts "Now calculating the Energy of the object."
puts M.to_i*C_to.i**2
end
$end
我也希望能够在课后被调用返回到clas选项。我确信这很容易,但我无法解决。
再次谢谢你,
罗斯。
那么,什么是问题?我只能看到该文中的陈述。 – DarkDust 2011-03-10 09:55:41