Re: Subclassing Struct.new
by Markus Werner other posts by this author
Feb 28 2006 5:54AM messages near this date
Re: Subclassing Struct.new
|
Re: Subclassing Struct.new
Hello,
Minkoo Seo wrote:
> Counter intuitive, at the very least. I really want this behavior to be
> fixed.
How should it be in your opinion?
I find it intuitive, cause the sense behind it is obviously.
Ruby assumes that a method call has the current object as receiver.
So it implied the "self." prefix"
But if there is a local var assignment it assumes that you like to use this
local var instead.
Since the local var is determined by the enclosing block it is IMHO an
intuitive solution.
What do you ruby expect to do if it see some think like this?
def foo
a = "hello"
end
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=".
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?
with kind regards
Markus
PS
What should happend in this case?
def n
@n
end
def n=(n)
@n = n
end
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
|