From: Dossy Date: 2002-08-23T20:52:04+09:00 Subject: Re: converting rows into structs On 2002.08.23, Eugene Scripnik wrote: > Friday, August 23, 2002, 2:19:53 PM, you wrote: > > D> Can I ask what the advantage of storing it as a Struct is? > > D> In all my Ruby/DBI code, I do something like this: > > D> def select(sql) > D> sth = $dbh.prepare(sql) > D> sth.execute > D> results = [] > D> sth.fetch_hash { |row| results << row.dup } > D> sth.finish > D> results > D> end > > D> Is there any advantage to having it be a Struct instead of an > D> Array of Hash'es? > I think there is no advantage, but I really like this syntax: > people.each { |man| puts "#{man.name} #{man.surname}" } > > This one is not so nice, isn't it? > people.each { |man| puts "#{man['name']} #{man['surname']}" } class Hash def method_missing(*args) self[args[0].to_s] end end ;-) -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)