ruby on rails - How can you parse just the first line of a CSV file? -
how can parse first line of csv file? want make sure of appropriate columns provided in file, don't want process whole file.
a better way of doing use built-in enumerable support in ruby's standard library csv parser:
headers = csv.open('file.csv', 'r') { |csv| csv.first }
the block result in file automatically being closed , call return array of parsed headers.
Comments
Post a Comment