From: "Eregon (Benoit Daloze)" Date: 2013-01-04T23:37:52+09:00 Subject: [ruby-core:51244] [ruby-trunk - Feature #7654] Add optional code block to IO::readlines Issue #7654 has been updated by Eregon (Benoit Daloze). Why not File.foreach('test.rb').map { |line| line.upcase } ? It does not create an intermediary Array. If you need to do other operations lazily (without an intermediate result), you could use #lazy: File.foreach('test.rb').lazy.select { |line| line.start_with? '/' }.map { |line| line.upcase }.to_a ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35210 Author: shock_one (������������������ ��������������) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method. -- http://bugs.ruby-lang.org/