[MacRuby-devel] Key-value observing
Jeremy Voorhis
jvoorhis at gmail.com
Tue May 12 10:18:02 PDT 2009
Hello,
I've been learning Cocoa, Objective-C and macruby in tandem and I was
just wondering, are there any plans to integrate the key-value
observing protocol with the attr_accessor family of methods? With a
little experimentation, I found KVO is definitely possible with
macruby, but the syntax is less than ideal (transcript made with the
0.4 release).
~ % macirb
>> class Notifier
>> attr_accessor :value
>> end
=> nil
>> class Observer
>> def observeValueForKeyPath(path, ofObject:object, change:change, context:context) puts change end
>> end
=> nil
>> n = Notifier.new
=> #<Notifier:0x8005e91a0>
>> n.addObserver(Observer.new, forKeyPath:'value', options:0, context:nil)
=> nil
>> n.value = 42
=> 42
>> n.setValue 42
{"kind"=>1}
=> nil
Best,
Jeremy Voorhis
More information about the MacRuby-devel
mailing list