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
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.