From: John Lam Date: 2006-05-04T09:42:32+09:00 Subject: Ruby idiom for attributes / properties ------=_Part_71710_23776608.1146703347230 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm writing a bunch of auto-marshaling code to let CLR code call back into Ruby. I just got the simplest possible marshaling scenario working today, which is letting you bind an Array of ActiveRecord objects to a CLR DataGridView control. See http://www.iunknown.com/articles/2006/05/03/activerecord-and-windows-formsf= or a longer discussion and a screenshot. Bottom line is that I can now write: data_grid.data_source =3D Person.find_by_last_name('Lam') Now, here's my problem: I'm not all that happy that I'm special casing my code for ActiveRecord objects. However, since Ruby doesn't have a mechanism for runtime-discovery of attributes, I'm special casing for ActiveRecord since it provides an @attributes hashtable with the name-value pairs for al= l attributes in the object. This makes it easy for me to generate the CLR anonymous class + object that implements the marshaling code that retrieves the attribute data from the Ruby ActiveRecord object (think about this as marshal by reference). Do folks have suggestions for implementing a discoverable attribute / property idiom in Ruby? Perhaps via a mixin module in the standard library? Or has this been done already and I'm just showing my Ruby newbiness? Thanks -John http://www.iunknown.com ------=_Part_71710_23776608.1146703347230--