From: Nobuyoshi Nakada Date: 2003-01-23T21:43:11+09:00 Subject: Re: Feature request: Array.to_h (2nd part!) Hi, At Thu, 23 Jan 2003 19:43:33 +0900, NAKAMURA, Hiroshi wrote: > > Isn't there a CSV processing library available? I imagine an API > > would provide hash-like access: > > > > data = CSV.new(filename) > > data.each do |record| > > # access record[:year], etc. > > end > > There is a csv processing module here: > http://www.ruby-lang.org/raa/list.rhtml?name=csv > But it doesn't do anything special treatment about > "the first line as column header." You must write like below now. If it is possible to override Row definition in particular subclass/instance, you could write like this. require 'csv' csv = CSV.open(filename, "r") (csv.row_class = Class.new(CSV::Row)).class_eval do csv.shift.each_with_index do |name, idx| define_method(name) {at(idx)} # class_eval("def #{name} at(#{idx})") end end csv.each do |record| p record.year end -- Nobu Nakada