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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -