Skip to content

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

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>
See also #dig #each_pair #delete_if #fetch also in 3.3 · 3.2 · 3.0