https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112009-07-16T16:17:16ZRuby Issue Tracking SystemRuby master - Bug #1666: Confusion in documentation for lines vs each_line, etc...https://redmine.ruby-lang.org/issues/1666?journal_id=47592009-07-16T16:17:16Zyugui (Yuki Sonoda)yugui@yugui.jp
<ul><li><strong>Assignee</strong> set to <i>yugui (Yuki Sonoda)</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Bug #1666: Confusion in documentation for lines vs each_line, etc...https://redmine.ruby-lang.org/issues/1666?journal_id=85172010-03-02T21:07:00Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<blockquote>
<p>Currently, IO#lines is defined as "to_enum(:each_line, *args)" and thus will ignore a block if one is given.<br>
On the other hand, String#lines and String#each_line are aliases, and thus will both execute the block, if one given. The same is true for StringIO#lines and StringIO#each_line.</p>
</blockquote>
<p>I think the inconsistency is caused by accident. Traditionally,<br>
String#lines had returned an Enumerator ignoring a given block.<br>
And it was changed at r11186 because of <a href="https://blade.ruby-lang.org/ruby-core/9218">[ruby-core:09218]</a>.<br>
I can find no reason why IO#lines are not changed similarly.<br>
I guess it is just forgotten.</p>
<p>In addition, ARGF works similarly to String:</p>
<p>$ echo -e "foo\nbar\nbaz" | ./ruby -e '$<.lines {|x| p x }'<br>
"foo\n"<br>
"bar\n"<br>
"baz\n"</p>
<p>$ echo -e "foo\nbar\nbaz" | ./ruby -e 'p $<.to_io.lines {|x| p x }'</p>
<p>This is apparently strange. So, I'll fix it soon by changing IO#<br>
lines, etc. I'll also fix RubySpec.<br>
(Of course, I'll revert this if matz says this is intended)</p>
<blockquote>
<p>the documentation is different for String#lines vs String#each_line, #bytes vs #each_byte, #chars vs #each_char (although they are aliases).</p>
</blockquote>
<p>Seems the same historical reason.</p>
<p>However, I wonder matz may still want people to use #each_line to<br>
iterate and #lines to make an Enumerator, respectively.</p>
<blockquote>
<p>StringIO#bytes, #lines & #chars are not documented at all.<br>
In all cases, the documentation for String should be cleaned up</p>
</blockquote>
<p>As you can see, my English is very poor. So I'll leave it to you.<br>
Before you commit, please let us review a patch.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Bug #1666: Confusion in documentation for lines vs each_line, etc...https://redmine.ruby-lang.org/issues/1666?journal_id=85182010-03-02T21:27:05Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r26797.<br>
Marc-Andre, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p> Ruby master - Bug #1666: Confusion in documentation for lines vs each_line, etc...https://redmine.ruby-lang.org/issues/1666?journal_id=88802010-03-09T13:00:41Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>=begin<br>
Documentation fixed in r26844.<br>
=end</p>