From: Joel VanderWerf Date: 2010-09-15T05:45:55+09:00 Subject: Re: Declarative relations between object attributes On 09/13/2010 11:46 PM, Knut Franke wrote: > 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. :) > 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 I was going to say: why not just do def self.caption "#{self.role}: #{self.name} <#{self.email}>" end but the calculate method makes it possible to observe(:caption), right? How does #observe know that caption depends on #role, #name, and #email? It seems difficult to determine (efficiently) whether to call the caption observers when one of the cells changes. The fact that caption depends on role, name, and email (but no others) is embedded opaquely in a proc. Maybe I should just read your code ;)