Skip to content

Commit 7816a04

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#each_line
1 parent 17eee25 commit 7816a04

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

doc/string/each_line.rdoc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
With a block given, forms the substrings ("lines")
1+
With a block given, forms the substrings (lines)
22
that are the result of splitting +self+
3-
at each occurrence of the given line separator +line_sep+;
3+
at each occurrence of the given +record_separator+;
44
passes each line to the block;
5-
returns +self+:
5+
returns +self+.
66

7+
With the default +record_separator+:
8+
9+
$/ # => "\n"
710
s = <<~EOT
811
This is the first line.
912
This is line two.
1013

1114
This is line four.
1215
This is line five.
1316
EOT
14-
1517
s.each_line {|line| p line }
1618

1719
Output:
@@ -22,9 +24,10 @@ Output:
2224
"This is line four.\n"
2325
"This is line five.\n"
2426

25-
With a different +line_sep+:
27+
With a different +record_separator+:
2628

27-
s.each_line(' is ') {|line| p line }
29+
record_separator = ' is '
30+
s.each_line(record_separator) {|line| p line }
2831

2932
Output:
3033

@@ -34,7 +37,7 @@ Output:
3437
"line four.\nThis is "
3538
"line five.\n"
3639

37-
With +chomp+ as +true+, removes the trailing +line_sep+ from each line:
40+
With +chomp+ as +true+, removes the trailing +record_separator+ from each line:
3841

3942
s.each_line(chomp: true) {|line| p line }
4043

@@ -46,15 +49,18 @@ Output:
4649
"This is line four."
4750
"This is line five."
4851

49-
With an empty string as +line_sep+,
52+
With an empty string as +record_separator+,
5053
forms and passes "paragraphs" by splitting at each occurrence
5154
of two or more newlines:
5255

53-
s.each_line('') {|line| p line }
56+
record_separator = ''
57+
s.each_line(record_separator) {|line| p line }
5458

5559
Output:
5660

5761
"This is the first line.\nThis is line two.\n\n"
5862
"This is line four.\nThis is line five.\n"
5963

6064
With no block given, returns an enumerator.
65+
66+
Related: see {Iterating}[rdoc-ref:String@Iterating].

string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9677,8 +9677,8 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, VALUE ary)
96779677

96789678
/*
96799679
* call-seq:
9680-
* each_line(line_sep = $/, chomp: false) {|substring| ... } -> self
9681-
* each_line(line_sep = $/, chomp: false) -> enumerator
9680+
* each_line(record_separator = $/, chomp: false) {|substring| ... } -> self
9681+
* each_line(record_separator = $/, chomp: false) -> enumerator
96829682
*
96839683
* :include: doc/string/each_line.rdoc
96849684
*

0 commit comments

Comments
 (0)