Estoy intentando crear un menú en Ruby para que, dependiendo de lo que ingresa un usuario, dependa de a qué clase se llame. Luego, afterwords volverá al "Principal" o la clase "Opciones" en este caso.Menú de opciones en Ruby
Espero que alguien me pueda ayudar. Aquí está mi código.
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
También me gustaría poder después de que se haya llamado a la clase para volver a las opciones de clas. Estoy seguro de que esto es fácil, pero no puedo resolverlo.
Gracias de nuevo,
Ross.
Entonces, ¿cuál es la pregunta? Solo puedo ver las declaraciones en ese texto. – DarkDust