End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CSV#each
csv.each → enumerator
csv.each {|row| ...}
lib/csv.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/csv.rb, line 2344
def each(&block)
parser_enumerator.each(&block)
end
Calls the block with each successive row. The data source must be opened for reading.
Without headers:
Example
string = "foo,0\nbar,1\nbaz,2\n" csv = CSV.new(string) csv.each do |row| p row end
Output:
Example
["foo", "0"] ["bar", "1"] ["baz", "2"]
With headers:
Example
string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" csv = CSV.new(string, headers: true) csv.each do |row| p row end
Output:
<CSV::Row "Name":"foo" "Value":"0"> <CSV::Row "Name":"bar" "Value":"1"> <CSV::Row "Name":"baz" "Value":"2">
Raises an exception if the source is not opened for reading:
Example
string = "foo,0\nbar,1\nbaz,2\n" csv = CSV.new(string) csv.close # Raises IOError (not opened for reading) csv.each do |row| p row end