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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -