Zachary Holt wrote:
> On Jun 6, 2007, at 10:47 PM, Joshua Ballanco wrote:
> 
>> Hey all!
> Hey
> 
>> Is there a good method for implementing Key-Value Observing in Ruby?
> Check out the Observable module.
> 
> http://ruby-doc.org/core/classes/Observable.html

Hmm...how did I miss that? This should do very well for the project I'm 
currently working on.

However, looking through the Observable module, I see one major 
downside: it's not automatic. That is, the Observable module should work 
well enough for custom classes, but what about Built-in and Standard 
Library classes? If, say, you wanted to be notified when the length of a 
string was changed, you would have to extend the String class, but then 
also implement a method to constantly observe the length...or am I 
missing something here? The way I understand how this works in Cocoa is 
that isa-swizzling is used to replace the class of the property being 
observed with a thin pseudo-class that notifies any registered observers 
when a change is made, then passes the change to the original class.

Is there a good reason not to do things this way? to do things this way? 
The only KVO implementation that I've ever used is Cocoa's, so I'm just 
curious about how/why it's done in Ruby. If I'm making a big fuss over 
nothing please feel free to say so.

-- 
Posted via http://www.ruby-forum.com/.