Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

CSV::Row#delete_if

row.delete_if {|header, value| ... } → self

Removes fields from self as selected by the block; returns self.

Removes each field for which the block returns a truthy value:

Example
source = "Name,Name,Name\nFoo,Bar,Baz\n"
table = CSV.parse(source, headers: true)
row = table[0]
row.delete_if {|header, value| value.start_with?('B') } # => true
row # => #<CSV::Row "Name":"Foo">
row.delete_if {|header, value| header.start_with?('B') } # => false

If no block is given, returns a new Enumerator:

Example
row.delete_if # => #<Enumerator: #<CSV::Row "Name":"Foo">:delete_if>
See also #delete #dig #deconstruct_keys #each also in 3.2 · 3.1 · 3.0