str.each_line(separator=$/) {|substr| block } â str
str.each_line(separator=$/) â an_enumerator
str.each_line(separator=$/) â an_enumerator
Instance Public methods
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.
1 2 3 4 5 6 | 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:
1 2 3 4 5 6 7 8 9 10 11 | Example one "hello\n" "world" Example two "hel" "l" "o\nworl" "d" Example three "hello\n\n\n" "world" |
Please login to continue.