Method: IO#readlines
- Defined in:
- io.c
permalink #readlines(sep = $/[, getline_args]) ⇒ Array #readlines(limit[, getline_args]) ⇒ Array #readlines(sep, limit[, getline_args]) ⇒ Array
Reads all of the lines in ios, and returns them in an array. Lines are separated by the optional sep. If sep is nil
, the rest of the stream is returned as a single record. If the first argument is an integer, or an optional second argument is given, the returning string would not be longer than the given value in bytes. The stream must be opened for reading or an IOError will be raised.
f = File.new("testfile")
f.readlines[0] #=> "This is line one\n"
f = File.new("testfile", chomp: true)
f.readlines[0] #=> "This is line one"
See IO.readlines for details about getline_args.
3897 3898 3899 3900 3901 3902 3903 3904 |
# File 'io.c', line 3897
static VALUE
rb_io_readlines(int argc, VALUE *argv, VALUE io)
{
struct getline_arg args;
prepare_getline_args(argc, argv, &args, io);
return io_readlines(&args, io);
}
|