Automagic

i am bringing a discussion over from the GUtopIa mailing list to get
some more general input on the problem of “automagical” bindings.

one of the main goals of gutopia is to be able to bind model data (i.e.
core-application data) to a gui interface such that changes to the data
are automatically reflected by specified changes in the gui.

we have thus far accomplished this, to a degree, by dynamically
modifying methods in the model to call on requested changes to the
interface. while adaquate and usable, in so far as it goes, i see
number of shortcomings that need to be addressed.

here’s the basic problem. if your are trying to bind to an array, for
example, in the model, how are you going to “trap” changes to that
array? a model may alter the array via #<< or #sort! or the like, and
such changes are indifferent to accessor_methods. indeed, you can alter
an array in this way via an attr_reader method!

so i was wondering if any of the ruby-talk crew had some ideas.

by the way, if you find this thread at all interesting we could still
use a number of additional minds involved with gutopia. join the mailing
list!

~transami

My first thought is that you redefine all of these
methods so that they trap changes and then call
the original corresponding methods.

As for someone modifying an array through an
attr_reader method… tell 'em, “Don’t do that.”

Hal

···

----- Original Message -----
From: “Tom Sawyer” transami@transami.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, August 08, 2002 1:59 AM
Subject: automagic

here’s the basic problem. if your are trying to bind to an array, for
example, in the model, how are you going to “trap” changes to that
array? a model may alter the array via #<< or #sort! or the like, and
such changes are indifferent to accessor_methods. indeed, you can alter
an array in this way via an attr_reader method!

MetaRuby (http://artengine.ca/matju/MetaRuby/) does what you want. It
contains a program that allows making arrays and hashes that have #undo
and #redo methods. That program is ~100 lines. I think one can write a
program for observable arrays and hashes (using MetaRuby too) in less than
50 lines.

···

On Thu, 8 Aug 2002, Tom Sawyer wrote:

here’s the basic problem. if your are trying to bind to an array, for
example, in the model, how are you going to “trap” changes to that
array? a model may alter the array via #<< or #sort! or the like, and
such changes are indifferent to accessor_methods. indeed, you can alter
an array in this way via an attr_reader method!


Mathieu Bouchard http://artengine.ca/matju