我想在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