@@ -30,7 +30,7 @@ Output:
3030With only string argument ` sep ` given,
3131reads lines using that string as the record separator:
3232
33- ```
33+ ``` ruby
3434strio = StringIO .new (TEXT )
3535strio.each_line(' ' ) {|line | p line }
3636```
@@ -51,7 +51,7 @@ With only integer argument `limit` given,
5151reads lines using the default record separator;
5252also limits the size (in characters) of each line to the given limit:
5353
54- ```
54+ ``` ruby
5555strio = StringIO .new (TEXT )
5656strio.each_line(10 ) {|line | p line }
5757```
@@ -69,12 +69,13 @@ Output:
6969"Fifth line"
7070"\n"
7171```
72+
7273** Arguments ` sep ` and ` limit ` **
7374
7475With arguments ` sep ` and ` limit ` both given,
7576honors both:
7677
77- ```
78+ ``` ruby
7879strio = StringIO .new (TEXT )
7980strio.each_line(' ' , 10 ) {|line | p line }
8081```
@@ -99,7 +100,7 @@ As stated above, method `each` _remaining_ line in the stream.
99100In the examples above each ` strio ` object starts with its position at beginning-of-stream;
100101but in other cases the position may be anywhere (see StringIO#pos):
101102
102- ```
103+ ``` ruby
103104strio = StringIO .new (TEXT )
104105strio.pos = 30 # Set stream position to character 30.
105106strio.each_line {|line | p line }
@@ -128,6 +129,7 @@ strio.each_line {|line| p line }
128129
129130Output:
130131
132+ ```
131133"んにちは"
132134"\x82\x93にちは"
133135"\x93にちは"
@@ -138,7 +140,7 @@ Output:
138140Like some methods in class ` IO ` , StringIO.each honors two special record separators;
139141see {Special Line Separators}[ https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Special+Line+Separator+Values ] .
140142
141- ```
143+ ``` ruby
142144strio = StringIO .new (TEXT )
143145strio.each_line(' ' ) {|line | p line } # Read as paragraphs (separated by blank lines).
144146```
@@ -150,7 +152,7 @@ Output:
150152"Fourth line\nFifth line\n"
151153```
152154
153- ```
155+ ``` ruby
154156strio = StringIO .new (TEXT )
155157strio.each_line(nil ) {|line | p line } # "Slurp"; read it all.
156158```
@@ -166,7 +168,7 @@ Output:
166168With keyword argument ` chomp ` given as ` true ` (the default is ` false ` ),
167169removes trailing newline (if any) from each line:
168170
169- ```
171+ ``` ruby
170172strio = StringIO .new (TEXT )
171173strio.each_line(chomp: true ) {|line | p line }
172174```
@@ -183,4 +185,5 @@ Output:
183185
184186With no block given, returns a new {Enumerator}[ https://docs.ruby-lang.org/en/master/Enumerator.html ] .
185187
188+
186189Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint.
0 commit comments