Project

General

Profile

Actions

Feature #4778

closed

IO#each_chomped

Feature #4778: IO#each_chomped

Added by yimutang (Joey Zhou) over 14 years ago. Updated about 13 years ago.

Status:
Rejected
Target version:
-
[ruby-core:36463]

Description

When manipulating text files, mostly, the input record separator(saying "\n") is scrap and will be chomped.

I suggest a method IO#each_chomped directly yielding the record with input record separator chomped.

Laziness is a virtue..

Joey


Files

feature4778.pdf (56.3 KB) feature4778.pdf Eregon (Benoit Daloze), 07/01/2012 07:32 AM

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 14 years ago Actions #1 [ruby-core:36464]

I wouldn't say this is about laziness, but about code readability. I agree this is a common use, but doesn't each_line already do that?

Updated by yimutang (Joey Zhou) over 14 years ago Actions #2 [ruby-core:36467]

Rodrigo Rosenfeld Rosas wrote:

I wouldn't say this is about laziness, but about code readability. I agree this is a common use, but doesn't each_line already do that?

No, #each_line is just a synonym of #each.

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 14 years ago Actions #3 [ruby-core:36468]

Yes, I was confused by the fact that puts already chomps the argument...

Updated by naruse (Yui NARUSE) over 14 years ago Actions #4 [ruby-core:36705]

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

Updated by headius (Charles Nutter) over 14 years ago Actions #5 [ruby-core:36836]

Trivial Ruby impl...

class IO
def each_chomped
each {|x| yield x.chomp!}
end
end

Of course if you don't mind the whole file being read into memory:

io.each.map(&:chomp).each { ...

Might be a way to pipeline that without reading into memory.

Updated by josb (Jos Backus) over 14 years ago Actions #6 [ruby-core:36854]

Charles, shouldn't

x.chomp!

be

x.chomp

in the above code? x.chomp! can return nil.

Updated by headius (Charles Nutter) over 14 years ago Actions #7 [ruby-core:36865]

Yeah, probably...or it should be x.chomp!; yield x

My intent was to avoid creating a useless transient object.

  • Charlie (mobile)

On Jun 8, 2011, at 10:54, Jos Backus wrote:

Issue #4778 has been updated by Jos Backus.

Charles, shouldn't

x.chomp!

be

x.chomp

in the above code? x.chomp! can return nil.

Feature #4778: IO#each_chomped
http://redmine.ruby-lang.org/issues/4778

Author: Joey Zhou
Status: Assigned
Priority: Normal
Assignee: Yukihiro Matsumoto
Category:
Target version:

When manipulating text files, mostly, the input record separator(saying "\n") is scrap and will be chomped.

I suggest a method IO#each_chomped directly yielding the record with input record separator chomped.

Laziness is a virtue..

Joey

--
http://redmine.ruby-lang.org

Updated by Eregon (Benoit Daloze) over 13 years ago Actions #8 [ruby-core:46028]

Attached one-minute slide for this proposal.
I think the name might still be matter of discussion (it could maybe even be an option of #each_line), but it would be interesting to get the general idea evaluated.

Updated by mame (Yusuke Endoh) over 13 years ago Actions #9 [ruby-core:46072]

Received, thank you!

I missed (or forgot) this feature request, but I love it.
Thank you putting this in the spotlight!

--
Yusuke Endoh

Updated by trans (Thomas Sawyer) over 13 years ago Actions #10 [ruby-core:46081]

How about just each_chomp(str="\n") ?

Updated by mame (Yusuke Endoh) about 13 years ago Actions #11 [ruby-core:46661]

  • Status changed from Assigned to Rejected

Benoit Daloze,

Sorry but this proposal was rejected at the developer meeting (7/21).

Both feature itself and name are not so bad.
But the reason it was rejected is fear of endless similar proposals.

So, please start it as a gem.
Matz might reconsider it if your gem really becomes widely used.

--
Yusuke Endoh

Actions

Also available in: PDF Atom