On 09/14/2010 02:14 PM, Knut Franke wrote:
> 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).

Oh, better watch out for evaluations with branches then:

class PublicEmailRole
   ...
  def to_s; ...; end
end

calculate(:caption) do
   case role
   when PublicEmailRole
     "#{self.role}: #{self.name} <#{self.email}>"
   else
     "#{self.role}: #{self.name}"
   end
end