From: James Edward Gray II Date: 2006-03-29T09:05:06+09:00 Subject: Re: [ANN] Article: An Exercise in Metaprogramming with Ruby On Mar 24, 2006, at 2:28 PM, James Edward Gray II wrote: > On Mar 24, 2006, at 1:38 PM, rubyhacker@gmail.com wrote: > >> I failed to post this link before, so here it is now: >> >> http://www.devsource.com/article2/0,1895,1928561,00.asp > > That's so darn cool, I think I'm just going to have to add it to > FasterCSV... ;) Developer at play: $ irb -r lib/faster_csv.rb >> class FullName < Struct.new(:first, :last) >> def initialize( first, last, other = Hash.new ) >> super(first, last) >> @middle, @suffix = other.values_at(:middle, :suffix) >> end >> attr_accessor :middle, :suffix >> end => nil >> names = [ FullName.new("Santa", "Clause"), ?> FullName.new("James", "Gray", :middle => "Edward", :suffix => "II"), ?> FullName.new("Easter", "Bunny") ] => [#, #, #] >> csv = FasterCSV.dump(names) => "class,FullName\n@middle,@suffix,first=,last=\n,,Santa,Clause \nEdward,II,James,Gray\n,,Easter,Bunny\n" >> puts csv class,FullName @middle,@suffix,first=,last= ,,Santa,Clause Edward,II,James,Gray ,,Easter,Bunny => nil >> reloaded = FasterCSV.load(csv) => [#, #, #] >> reloaded.find { |name| name.first == "James" }.middle => "Edward" That's using the development version of FasterCSV. Thanks for the idea Hal! ;) James Edward Gray II