Method: String#each_line
- Defined in:
- string.c
#each_line(separator = $/) {|substr| ... } ⇒ String #each_line(separator = $/) ⇒ Object
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.
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\n"
"world"
7128 7129 7130 7131 7132 |
# File 'string.c', line 7128
static VALUE
rb_str_each_line(int argc, VALUE *argv, VALUE str)
{
return rb_str_enumerate_lines(argc, argv, str, 0);
}
|