Ruby循环直到出问题
发布时间:2020-12-17 02:43:30 所属栏目:百科 来源:网络整理
导读:对原始问题进行重新澄清.我需要一个将在 ruby中运行的循环,并允许我进入命令停止进入控制台(可能使用gets)然后循环将停止. 干杯 马丁 解决方法 我想你可以使用这样的东西: # Initialize the input queue. This is where the user-created info will be stor
对原始问题进行重新澄清.我需要一个将在
ruby中运行的循环,并允许我进入命令停止进入控制台(可能使用gets)然后循环将停止.
干杯 解决方法
我想你可以使用这样的东西:
# Initialize the input queue. This is where the user-created info will be stored $QUEUE = [] def pending old = $QUEUE $QUEUE = [] old end t = Thread.new do loop do # Ask the user for something print "Enter info here: " # Read information in $QUEUE << gets.chomp end end # Example code utilizing this; you can do whatever you like with the queue 2.times do sleep 5 # Print the list out puts "nYou entered: n" << pending.join("n") end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |