How to restore input from within a loop or similar?

Hi,

I currently have a pseudo irc client.

I use something like this here to get what I type:

select( [$stdin], nil, nil, 1.5 )

I do this from within a big loop that reads in user input, like so:

loop {

user_input = $stdin.gets.chomp
case user_input
when ‘test’
puts ‘Just testing…’
when ‘irc’
# here the code to start the IRC client, which has that select()
call
end
break if user_input == ‘quit’

}

My question is, when I input ‘irc’, how do I stop only that select()
call, and return control back to the user_input loop?

Right now, if I use “exit” within the IrcClient class, I stop the whole
program, but I only want to stop the Irc client

Hi,

so you want to pass control back to the loop from within the select()
method? That’s not directly possible, because the method isn’t aware of
its context. What you could do is let the method return a specific
“stop value” (e. g. nil) and then do a “next” inside the loop body to
jump to the next iteration:

next if select([$stdin], nil, nil, 1.5).nil?

But I’m not really sure what your code looks like and what you want.

Marc H. wrote in post #1081649:

Right now, if I use “exit” within the IrcClient class, I stop the whole
program, but I only want to stop the Irc client

exit stops the whole program

return returns from a method (so the easiest solution is just to move
that logic into a method, and call it from the appropriate place

Otherwise there’s throw and catch

when ‘irc’
catch(:done) do

throw :done # to jump out of the catch block

end