Method: String#each_line
- Defined in:
- string.c
#each(separator = $/) {|substr| ... } ⇒ String #each_line(separator = $/) {|substr| ... } ⇒ String
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 on \n characters, except that multiple successive newlines are appended together.
print "Example one\n"
"hello\nworld".each {|s| p s}
print "Example two\n"
"hello\nworld".each('l') {|s| p s}
print "Example three\n"
"hello\n\n\nworld".each('') {|s| p s}
produces:
Example one
"hello\n"
"world"
Example two
"hel"
"l"
"o\nworl"
"d"
Example three
"hello\n\n\n"
"world"
3670 3671 3672 |
# File 'string.c', line 3670 static VALUE rb_str_each_line(argc, argv, str) int argc; |