Method: CSV::Table#delete_if
- Defined in:
- lib/csv.rb
#delete_if(&block) ⇒ Object
Removes any column or row for which the block returns true. In the default mixed mode or row mode, iteration is the standard row major walking of rows. In column mode, iteration will yield two element tuples containing the column name and an Array of values for that column.
This method returns the table for chaining.
820 821 822 823 824 825 826 827 828 829 830 831 832 |
# File 'lib/csv.rb', line 820 def delete_if(&block) if @mode == :row or @mode == :col_or_row # by index @table.delete_if(&block) else # by header to_delete = Array.new headers.each_with_index do |header, i| to_delete << header if block[[header, self[header]]] end to_delete.map { |header| delete(header) } end self # for chaining end |