I'm trying to find out if I can delete an array with a method called on itself. array.clear removes all elements, but not the array itself.
Context
Here is the context. I have a CSV file with no headers. I want to be able to delete a row given one value in the row. So, the user can pass me "Chocolate", I seach the CSV and delete the row with Chocolate as the first value.
CSV file
Chocolate, some description blah
Cheese, some description about this one
Ruby file
require 'csv'
def remove_recipe(recipe_name)
CSV.foreach(csv_file_path, w+) do |row|
row.clear??? if row[0] == recipe_name
end
end
I could add a header but I'd like to know if it's possible without.
Ok, to describe the input and output as Sawa has asked: A user will input string "Chocolate". I will search the CSV file for that string. If present, I want to update the CSV file to remove the row containing that string.