Actions
Feature #12553
closedIO.readlines(filename, chomp: true)
Status:
Closed
Assignee:
-
Target version:
-
Description
IO.readlinesやIO.foreach、IO#each_lineなどは戻り値(またはブロックパラメータ)のそれぞれの「行」に改行を含みます。
POSIXの "Line" の定義は末尾の改行を含んでのものなので非常に正しい挙動なのですが、正直不便です。
A sequence of zero or more non- characters plus a terminating character.
例えば IO.readlines(filename, chomp: true) などで改行を最初から削ってくれませんか
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"]
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
Like0
Like0Like0Like0Like0