On Thu, Mar 29, 2007 at 04:45:37AM +0900, Andrew Libby wrote:
> Nice!  That's great Brian, I love it.  A quick
> fix to the code I posted previously makes use of
> this class.  My class extends OpenStruct, and no longer
> has an @attributes attribute, or a method_missing
> method.
> 
> Thanks!

NP. Depending on how dynamic you want to be, it's smaller with Struct:

#!/usr/bin/ruby

require 'csv'

class ObjectCsvParser
    def self.each_record(fn,&block)
        klass = nil
        CSV.open(fn,'r') do |line|
            if klass.nil?
                klass = Struct.new( *line.map { |l| l.downcase.to_sym } )
                next
            end

            yield klass.new(*line)
        end
    end
end

# Assuming your CSV has last, first, and email as  fields
ObjectCsvParser.each_record(ARGV.shift) do |record|
    puts "Last: " + record.last
    puts "First: " + record.first
    puts "Email: " + record.email
end