static public Method

IO.readlines(...)

IO.readlines(name, sep_string=$/)    array

Reads the entire file specified by name as individual lines, and returns those lines in an array. Lines are separated by sep_string.

a = IO.readlines("testfile")
a[0]   #=> "This is line one\n"

Source Code

/*
*  call-seq:
*     IO.readlines(name, sep_string=$/)   => array
*  
*  Reads the entire file specified by <i>name</i> as individual
*  lines, and returns those lines in an array. Lines are separated by
*  <i>sep_string</i>.
*     
*     a = IO.readlines("testfile")
*     a[0]   #=> "This is line one\n"
*     
*/

static VALUE
rb_io_s_readlines(argc, argv, io)
   int argc;
   VALUE *argv;
   VALUE io;
{
   VALUE fname;
   struct foreach_arg arg;

   rb_scan_args(argc, argv, "11", &fname, &arg.sep);
   SafeStringValue(fname);

   arg.argc = argc - 1;
   arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
   if (NIL_P(arg.io)) return Qnil;
   return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.