summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--lib/csv.rb8
-rwxr-xr-xtest/csv/test_interface.rb8
3 files changed, 20 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index c06a3b5b58..38e428c403 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
+Thu May 27 00:34:07 2011 James Edward Gray II <jeg2@ruby-lang.org>
+
+ * lib/csv.rb: Enhance each() to support Enumerator.
+
Thu May 26 10:32:11 2011 James Edward Gray II <jeg2@ruby-lang.org>
- * 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@gmail.com>
diff --git a/lib/csv.rb b/lib/csv.rb
index 48c2e97eda..c7649b8842 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1787,8 +1787,12 @@ class CSV
# 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
diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb
index 92da39cebc..785f43126b 100755
--- a/test/csv/test_interface.rb
+++ b/test/csv/test_interface.rb
@@ -112,6 +112,14 @@ class TestCSV::Interface < TestCSV
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 ###