From: Dossy Date: 2002-05-09T04:03:21+09:00 Subject: Re: gets and eof? On 2002.05.09, Paul Brannan wrote: > However, when I first wrote it, I instead wrote: > > loop do > line = $stdin.gets > break if $stdin.eof? > puts "<-- #{line}" > end > > The first case works correctly. The second case does not; when I type a > line, it doesn't show up until the second line is typed. This happens > whether I am using $stdin or whether I am using a socket (returned by > TCPServer#accept). Why does this happen in the second case? In the code shown, gets will read up to the line seperator which comes before the eof. So, the _second_ time through the loop, when gets tries to read, it'll hit the eof and then IO#eof? will be true. Life would get very scary if IO#eof? was asynchronous ... ;-) -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)