ruby-changes:19695
From: jeg2 <ko1@a...>
Date: Fri, 27 May 2011 00:35:13 +0900 (JST)
Subject: [ruby-changes:19695] jeg2:r31740 (trunk): * lib/csv.rb: Enhance each() to support Enumerator.
jeg2 2011-05-27 00:35:06 +0900 (Fri, 27 May 2011) New Revision: 31740 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31740 Log: * lib/csv.rb: Enhance each() to support Enumerator. Modified files: trunk/ChangeLog trunk/lib/csv.rb trunk/test/csv/test_interface.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31739) +++ ChangeLog (revision 31740) @@ -1,7 +1,11 @@ +Thu May 27 00:34:07 2011 James Edward Gray II <jeg2@r...> + + * lib/csv.rb: Enhance each() to support Enumerator. + Thu May 26 10:32:11 2011 James Edward Gray II <jeg2@r...> - * lib/csv.rb: Documentation improvements from Ysiad Ferreiras. - [Ruby 1.9 - Bug #4785] + * lib/csv.rb: Documentation improvements from Ysiad Ferreiras. + [Ruby 1.9 - Bug #4785] Thu May 26 15:42:02 2011 Cezary Baginski <cezary.baginski@g...> Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 31739) +++ lib/csv.rb (revision 31740) @@ -1787,8 +1787,12 @@ # The data source must be open for reading. # def each - while row = shift - yield row + if block_given? + while row = shift + yield row + end + else + to_enum end end Index: test/csv/test_interface.rb =================================================================== --- test/csv/test_interface.rb (revision 31739) +++ test/csv/test_interface.rb (revision 31740) @@ -112,6 +112,14 @@ assert_equal(nil, csv.shift) end end + + def test_enumerators_are_supported + CSV.open(@path, col_sep: "\t", row_sep: "\r\n") do |csv| + enum = csv.each + assert_instance_of(Enumerator, enum) + assert_equal(@expected.shift, enum.next) + end + end ### Test Write Interface ### -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/