Load a single-column CSV file into a Ruby array -


i new ruby.
below naive code load single-column csv file ruby array.

question: there better?
in particular, how not hard-code number of items?

require 'csv' countries = array.new(240) = 0 csv.foreach "#{rails_root}/config/countries.csv" |country|   countries[i] = country[0]   = + 1 end 

try this:

require 'csv' countries = csv.read("#{rails_root}/config/countries.csv").flatten 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -