On Feb 16, 2007, at 7:30 PM, Joe at CodeGear wrote:

> One use case that came to mind was for managing CSV files (esp. w/
> headers).  You could create a Struct for the file, using the header
> row from the file, passing a block to the new method to add a method
> to initialize it based on an array (as returned from the csv reader).

I really like the way you think:

#!/usr/bin/env ruby -w

require "rubygems"
require "faster_csv"

require "pp"

Name  = Struct.new(:first, :last)
names = [Name.new("James", "Gray"), Name.new("Joe")]

csv = FCSV.dump(names)
puts <<END_CSV
CSV
===
#{csv}
END_CSV

reloaded = FCSV.load(csv)
puts <<END_RUBY
Ruby
====
END_RUBY
pp reloaded
# >> CSV
# >> ===
# >> class,Name
# >> first=,last=
# >> James,Gray
# >> Joe,
# >>
# >> Ruby
# >> ====
# >> [#<struct Name first="James", last="Gray">,
# >>  #<struct Name first="Joe", last=nil>]

__END__

James Edward Gray II