From: Justin Collins Date: 2009-12-09T19:40:14+09:00 Subject: Re: a gets problem Ruby Newbee wrote: > On Wed, Dec 9, 2009 at 4:06 PM, Tamas Szabo wrote: > >> On Wed, Dec 9, 2009 at 3:41 PM, Ruby Newbee wrote: >> >> >>> On Wed, Dec 9, 2009 at 3:35 PM, Seebs wrote: >>> >>>> On 2009-12-09, Ruby Newbee wrote: >>>> >>>>> But when I re-executed x = gets it always got a nil. >>>>> Why this happens? Thank you. >>>>> >>>> Because you convinced it that it had reached the end of file, and gets >>>> returns a nil after you've reached end of file. >>>> >>>> >>> How to re-gets it then? >>> Thanks. >>> >>> >>> >> Why don't you just use ENTER instead of 2 CTRL-D-s when you are entering the >> line? >> >> > > why not? > > Mainly because gets is waiting for an EOL, not an EOF. Recall that, in this case, gets is reading from stdin. Once you tell it stdin is at the end of the file, it has no reason to continue reading from it. -Justin