readlines(...)
public
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]
Show source
/*
* 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]
*
*/
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(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}