--0016368e1e76239f58046d81c1c8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Mon, Jun 29, 2009 at 2:44 PM, Wijnand Wiersma <wijnand / videre.net> wrote: > Hi all, > > It seems writer methods don't work within blocks, the names are resolved to > new local variable names I guess. > It is funny however the reader method does seem to work fine. > Is it possible to make it work anyway without changing the syntax within > the block? > > My example gist: http://gist.github.com/137741 > You can override the getter method for a DSL-ish syntax: class Foo attr_accessor :bar def initialize(&block) instance_eval(&block) end def bar(v l) v ? @bar : @bar end end f oo.new { bar 2 } f.bar # 2 f.bar 3 f.bar # 3 f.bar f.bar # 4 HTH Mike > Kind regards, > Wijnand > > --0016368e1e76239f58046d81c1c8--