method
each_line
ruby latest stable - Class:
String
each_line(*args)public
Splits str using the supplied parameter as the record separator ($/ by default), passing each substring in turn to the supplied block. If a zero-length record separator is supplied, the string is split into paragraphs delimited by multiple successive newlines.
See IO.readlines for details about getline_args.
If no block is given, an enumerator is returned instead.
print "Example one\n" "hello\nworld".each_line {|s| p s} print "Example two\n" "hello\nworld".each_line ('l') {|s| p s} print "Example three\n" "hello\n\n\nworld".each_line ('') {|s| p s}
produces:
Example one "hello\n" "world" Example two "hel" "l" "o\nworl" "d" Example three "hello\n\n" "world"
static VALUE
rb_str_each_line(int argc, VALUE *argv, VALUE str)
{
RETURN_SIZED_ENUMERATOR(str, argc, argv, 0);
return rb_str_enumerate_lines(argc, argv, str, 0);
}