ruby - How to compare an array with the last inserted array in a csv file? -



ruby - How to compare an array with the last inserted array in a csv file? -

i generate arrays append file with:

require 'csv` csv.open(file_name, "a+") |csv| csv << array end

i want skip insertion if index [0] value identical lastly inserted array's [0].

how can read lastly line/row of csv file , compare it's values array that's still not inserted?

working around of @patru said:

require 'csv' csv = csv.open(file_name, "a+") first_row = csv.first csv.rewind last_row = csv.reverse_each.first csv << ary unless ary == first_row or ary == last_row

ruby arrays csv

Comments