From: Gary Wright Date: 2011-10-20T15:01:54+09:00 Subject: Re: Call method on attribute update On Oct 20, 2011, at 1:38 AM, Jason Lillywhite wrote: > If @yn is updated, automatically run method "foo.calcArea". The way I > have it now requires me to do: > > foo.yn = 100.0 > foo.calcArea > > There must be a way to let ruby call that method for me. Just define the attribute writer method yourself instead of using the helpers: class Foo attr_reader :yn def yn=(value) @yn = value calcArea end def calcArea puts "recomputing area" end end >> f = Foo.new #=> # >> f.yn = 100 #=> 100 recomputing area >> f.yn #=> 100 Gary Wright