Project

General

Profile

Actions

Feature #12553

closed

IO.readlines(filename, chomp: true)

Added by naruse (Yui NARUSE) over 8 years ago. Updated about 8 years ago.

Status:
Closed
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) などで改行を最初から削ってくれませんか

Updated by duerst (Martin Dürst) over 8 years ago

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

Updated by naruse (Yui NARUSE) about 8 years 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"]
Actions #4

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Status changed from Open to Closed

Applied in changeset r56581.


chomp option

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0