readlines(p1, p2 = v2, p3 = v3, p4 = v4, p5 = {})
public
Reads the entire file specified by name as individual lines, and
returns those lines in an array. Lines are separated by sep.
a = IO.readlines("testfile")
a[0]
If the last argument is a hash, it’s the keyword argument to open. See IO.read for detail.
Show source
static VALUE
rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
{
VALUE opt;
struct foreach_arg arg;
struct getline_arg garg;
argc = rb_scan_args(argc, argv, "13:", NULL, NULL, NULL, NULL, &opt);
extract_getline_args(argc-1, argv+1, &garg);
open_key_args(argc, argv, opt, &arg);
if (NIL_P(arg.io)) return Qnil;
extract_getline_opts(opt, &garg);
check_getline_args(&garg.rs, &garg.limit, garg.io = arg.io);
return rb_ensure(io_s_readlines, (VALUE)&garg, rb_io_close, arg.io);
}