From: Knut Franke Date: 2010-09-15T06:14:06+09:00 Subject: Re: Declarative relations between object attributes Joel VanderWerf wrote: > 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? Yes, for this example that's the main advantage. More generally, caption=() could do other interesting stuff; like updating a GUI (see model-view.rb). > How does #observe know that caption depends on #role, #name, and #email? By calling the block and keeping track of which cell getters are called (using a global variable). That's certainly not perfect, but compared to trying to parse the block content somehow it has the advantage of working also if the source cells are accessed indirectly via other methods (not to mention it's much easier to implement). > Maybe I should just read your code ;) If anything's still unclear: It's not much code, and I've tried to make it readable. :-) -- Posted via http://www.ruby-forum.com/.