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#delete_if
row.delete_if {|header, value| ... } → self
lib/csv/row.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/row.rb, line 476
def delete_if(&block)
return enum_for(__method__) { size } unless block_given?
@row.delete_if(&block)
self # for chaining
end
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>