Re: Subclassing Struct.new
by Chiaro Scuro other posts by this author
Feb 28 2006 6:35AM messages near this date
Re: Subclassing Struct.new
|
Re: Subclassing Struct.new
On 2/28/06, Markus Werner <markus.werner+news@[...].de> wrote:
> Should it assign the local var "a" or should it call the method "a="?
> If you say that it should assign the local var "a" just if there is no
> method "a=".
thanks for pointing out the side effects of the other stylistic
choice. now it's much clearer why it was done this way.
> What happend to your code if some day in the future you or some else define
> a methode "a=" to write the ivar @a. And you don't remember that your
> method foo use a local var a?
my tests would fail, I guess.
I also program in VBA, where you have a 'property set' feature that is
roughly the equivalent of the 'name=' operator in Ruby and it has
never been a problem. the few times this error slipped through, the
tests always caught it.
> What should happend in this case?
>
> def n
> @n
> end
>
> def n=(n)
> @n = n
> end
I guess the 'n' in '@n = n' would be the one most internally scoped,
i.e. the passed arg
--
-- Chiaroscuro --
Liquid Development Blog: http://feeds.feedburner.com/blogspot/liquiddevelopment
Thread:
Minkoo Seo
Chiaro Scuro
Minkoo Seo
Yukihiro Matsumoto
Mark Wilden
Markus Werner
Chiaro Scuro
Minkoo Seo
Minkoo Seo
Hal Fulton
mental
Ross Bamford
mental
Ross Bamford
Chiaro Scuro
Ross Bamford
Chiaro Scuro
Minkoo Seo
Chiaro Scuro
mental
Chiaro Scuro
mental
Yukihiro Matsumoto
Caleb Clausen
Yukihiro Matsumoto
Caleb Clausen
MenTaLguY
Yukihiro Matsumoto
gwtmp01
Chiaro Scuro
mental
Chiaro Scuro
mental
Logan Capaldo
Pit Capitain
|