From: CT Date: 2004-07-13T15:06:07+09:00 Subject: Re: gets On Tue, 13 Jul 2004 14:47:22 +0900, News Groups wrote: > Hello All, > > I am new to Ruby Language. I just want to read a string using 'gets' > function, but am getting the below error message. Welcome! > ERROR MESSAGE: `gets': Bad file descriptor (Errno::EBADF) You must be trying to run that code in the SciTE editor. Try running the program on the command line. I remember getting this sort of an error when I tried running a similar thing from SciTE. > Can anybody please help me in solving this problem. Is it required to > require any file to use 'gets' function. > > Thanks in Advance, > > Thanks & Regards, > Mohan > > Hope that helps, and no problem. Also, here's the ri doc for gets: (try the command 'ri' to get documentation on methods and such) C:\Files\Ruby>ri Kernel.gets ------------------------------------------------------------ Kernel#gets gets(separator=$/) => string or nil ------------------------------------------------------------------------ Returns (and assigns to +$_+) the next line from the list of files in +ARGV+ (or +$*+), or from standard input if no files are present on the command line. Returns +nil+ at end of file. The optional argument specifies the record separator. The separator is included with the contents of each record. A separator of +nil+ reads the entire contents, and a zero-length separator reads the input one paragraph at a time, where paragraphs are divided by two consecutive newlines. If multiple filenames are present in +ARGV+, +gets(nil)+ will read the contents one file at a time. ARGV << "testfile" print while gets _produces:_ This is line one This is line two This is line three And so on... The style of programming using +$_+ as an implicit parameter is gradually losing favor in the Ruby community.