From: Knut Franke Date: 2010-09-14T15:46:12+09:00 Subject: Re: Declarative relations between object attributes Joel VanderWerf wrote: > I wrote a library called observable for use in GUI MVC programming (with > FXRuby), something along those lines. One nice feature was pattern > matching on the changed value, so you could have separate handlers for > different ranges etc. Ruby's #=== methods are very cool and somewhat > underused. That might be a nice feature to add to your #observe method. > > Here's the code: > > http://redshift.sourceforge.net/observable/ Thanks for the link; I managed to miss that one when trying to google existing solutions. :-) I've taken the liberty to include some of the ideas in my code. > when_temperature 0..100 do > self.status = :on > end > > when_temperature 100..100000 do > self.status = :off > end It appears that for this particular example, your API is nicer than mine. ;-) Here's another one (distilled from model-view.rb) which probably better illustrates the idea behind the cells approach: class Model cell :name, :email, :role, :caption def initialize self.name = "Your Name" self.email = "user@example.com" self.role = "To" calculate(:caption) { "#{self.role}: #{self.name} <#{self.email}>" } end end -- Posted via http://www.ruby-forum.com/.