From: Chris Morris Date: 2002-05-20T02:22:19+09:00 Subject: RE: Object <-> Relational mapping > db.select_all(long_sql_statement) do |row| > foo = Foo.new > foo.a = row['a'] > foo.b = row['b'].to_i > foo.c = row['c'].to_f > #... > foo.z = row['z'] > end Some possible improvements. I'd try to take advantage of .send - so the loop would be something like: ... do |row| # row would need to be a hash row.each do |colname, colvalue| foo.send('=' + colname, colvalue) end end As far as handling row['b'].to_i, etc. -- if it has translate types, make that transformation in the set accessor method of foo's class. For a C# app I'm working, I use reflection to do a similar thing as the row loop above (although it ain't nearly so clean :). In addition, to write the C# classes that front the objects, I wrote a Ruby script that uses Ruby\ODBC to read all the column info out of a table and automatically write the C# class. It's not fully automated, but it saves on a lot of typing. You could probably do the same for Ruby classes (including automatically coding for translations from string to the actual column datatype). I don't know of any generic mapping lib efforts -- but I'd probably be able to contribute some as needs arise at work. Chris