End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CSV::Row#each
row.each {|header, value| ... } → self
lib/csv/row.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/row.rb, line 610
def each(&block)
return enum_for(__method__) { size } unless block_given?
@row.each(&block)
self # for chaining
end
Calls the block with each header-value pair; returns self:
Example
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.each {|header, value| p [header, value] }
Output:
Example
["Name", "Foo"] ["Name", "Bar"] ["Name", "Baz"]
If no block is given, returns a new Enumerator:
Example
row.each # => #<Enumerator: #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz">:each>