Project

General

Profile

Feature #12553

IO.readlines(filename, chomp: true)

Added by naruse (Yui NARUSE) about 1 year ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-dev:49711]

Description

IO.readlinesやIO.foreach、IO#each_lineなどは戻り値(またはブロックパラメータ)のそれぞれの「行」に改行を含みます。

POSIXの "Line" の定義は末尾の改行を含んでのものなので非常に正しい挙動なのですが、正直不便です。

3.206 Line

A sequence of zero or more non- characters plus a terminating character.

例えば IO.readlines(filename, chomp: true) などで改行を最初から削ってくれませんか

Associated revisions

Revision 56581
Added by nobu (Nobuyoshi Nakada) 9 months ago

chomp option

  • io.c (extract_getline_opts): extract chomp option. [Feature #12553]

Revision 56581
Added by nobu (Nobuyoshi Nakada) 9 months ago

chomp option

  • io.c (extract_getline_opts): extract chomp option. [Feature #12553]

History

#1 [ruby-dev:49712] Updated by duerst (Martin Dürst) about 1 year ago

ごもっともだと思います。

#3 [ruby-dev:49832] Updated by naruse (Yui NARUSE) 11 months ago

Nobuyoshi Nakada wrote:

とりあえず。

https://github.com/ruby/ruby/compare/trunk...nobu:feature/12553-chomp-option

これだと以下の通り\rが除かれないので、除かれた方がいいな。

% ruby -e'$><<"abc\r\ndef\r\nghi"'|./miniruby -e'p $<.each_line(chomp:true).to_a'
["abc\r", "def\r", "ghi"]
% ruby -e'$><<"abc\r\ndef\r\nghi"'|./miniruby -e'p $<.each_line.map(&:chomp).to_a'
["abc", "def", "ghi"]

#4 Updated by nobu (Nobuyoshi Nakada) 9 months ago

  • Status changed from Open to Closed

Applied in changeset r56581.


chomp option

  • io.c (extract_getline_opts): extract chomp option. [Feature #12553]

Also available in: Atom PDF