我想设置" vars [' dif']"根据" globalvars [' days']"的价值差异和" globalvars ['供应']" (设置' dif'天' - '供应')
任何能告诉我如何做到这一点的答案都会有所帮助,即使这意味着我需要完全改变我的代码,但我更希望它以我保存代码的方式完成。
globalvars = { 'days' => 0 , 'supplies' => 0 }
puts "Please input the number of days the trip will take."
globalvars['days'] = gets.chomp
puts "Please input the number of days worth of supplies each person can carry."
globalvars['supplies'] = gets.chomp
puts globalvars
puts ;
puts "Press RETURN to continue."
gets
if (globalvars['days'] <= globalvars['supplies'])
then
puts "No helpers are needed."
puts "Press RETURN to continue."
gets
else
puts "Helpers are needed."
puts "Press RETURN to continue."
gets
end
vars = { 'man' => 0 , 'varx' => 0 , 'dif' => 0 }
vars['man'] = globalvars['supplies']
vars['dif'] = globalvars['days'] - globalvars['supplies'] "< this is the line"
puts vars
puts ;
puts "Press RETURN to exit."
gets
如果有人知道如何使获取命令只接受某个键,例如输入,按下,请将其添加到您的答案中。