From: "Ara.T.Howard" Date: 2005-06-23T06:00:41+09:00 Subject: Re: [ANN] traits-0.3.0 On Thu, 23 Jun 2005, Joel VanderWerf wrote: > 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. good because it was giving me fits ;-) bascially it's tough to tell this trait 'a', 'default' => 42 from trait 'default' => 42 or this trait 'a', 'pre' => a_proc from this trait 'pre' => a_proc because i already allow this list syntax traits 'a', 'b', 'c' => 42', 'd' => 'forty-two' orthogonal is good! i didn't know about that btw... nice. cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================