Ruby loop until you get a problem

Reclassification on the first question. I need a loop that will work in ruby ​​and allow me to log into the console in the console (using, perhaps), and then the loop will stop.

Cheers Martin

+4
source share
1 answer

I think you could use something like this:

# 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 
+7
source

Source: https://habr.com/ru/post/1400778/


All Articles