From: Rick DeNatale Date: 2007-03-18T04:23:27+09:00 Subject: Re: attr_accessor question On 3/17/07, Stefano Crocco wrote: > Alle sabato 17 marzo 2007, Rick DeNatale ha scritto: > > > def var=value > > > @var=value > > > end > > > > Actually the setter should be > > > > def var=(value) > > @var=value > > end > > Do you mean I should put value into brackets? If so, why? To me, it seems that > my form works perfectly. Is there something I'm not aware of? I guess it's a matter of style. The pickaxe gives the syntax of a method definition as: def defname [( [arg [ =val], ...] [, *vararg ] [ , &blockarg ] ) ] body end Which implies that if arguments are present they must be enclosed in parentheses. I've always done so, and I can't recall having seen method *definitions* which omitted the parens around the args. But trying this with both ruby1.8 and ruby1.9 I see that it neither complains about the missing parens, something I didn't know until just now. But I greatly prefer using the parens. In fact my preference is to use them for most method invocations as well, although omitting them there is more common. I tend only to omit them in idiomatic cases like attr_accessor :foo, :bar instead of attr_accessor(:foo, :bar) or when ruby is being used as a domain specific language. I also notice that the pickaxe syntax is a little loose because it won't admit valid things like def foo(&block) ... end So it's really a pedagogical syntax. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/