From: Robert Klemme on
On 20.11.2009 18:14, Aldric Giacomoni wrote:
> Brian Candler wrote:
>> if gets.chomp! == "!quit" then
>> cleanupAndExit
>> else
>> puts gets.chomp!
>> end
>>
>> Note how gets is called twice.
>
> Also, I have a question...
>
> results = select([@sock, STDIN], nil, nil)
>
> for input in results[0]
> [...]
> end #for
> end #if
>
>
> Instead of doing a for loop - just do "results[0].each", which is more
> idiomatic.

Absolutely. Usually one would do

ios = [... ]

in, = select(ios)

in.each do |io|
data = io.read_nonblock 1024
...
end

> The question is, what does "select" do ? rdocs aren't helpful, and I
> don't understand that bit of code.

See Brian's explanation.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/