From: Joel VanderWerf Date: 2005-06-23T05:54:16+09:00 Subject: Re: [ANN] traits-0.3.0 Ralph "PJPizza" Siegler wrote: > On Wed, Jun 22, 2005 at 09:18:13PM +0900, Ara.T.Howard wrote: > >>URLS >> >> http://raa.ruby-lang.org/search.rhtml?search=traits >> http://codeforpeople.com/lib/ruby/traits >> >>ABOUT >> >> traits.rb aims to be a better set of attr_* methods and encourages better >> living through meta-programming and uniform access priciples. traits.rb >> supercedes attributes.rb. why? the name is shorter ;-) > > > Hello Ara, > > would it be possible to have a kind of observer on traits, kind of like Apple/obc/cocoa's KVO? > > > > Ralph "PJPizza" Siegler I'm not sure what those observers do, but the observable module on RAA can be used orthogonally with any pair of methods #attr and #attr=, as in the following example: [~] cat foo.rb require 'observable' class A def foo; 3; end def foo=(x); p x; end extend Observable observable :foo end a = A.new a.when_foo(Object) {|val| p "changing foo to #{val.inspect}"} a.foo = "zap" [~] ruby foo.rb "changing foo to 3" "zap" "changing foo to \"zap\"" So presumably this could be used with traits without modifying either library.