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-formsfor
a longer discussion and a screenshot.
Bottom line is that I can now write:
data_grid.data_source = 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
all
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