J
James Byrne
In the ruby language if I do this:
def g=( value )
@gval = value.to_s
end
def g
@gval
end
g = 12
Then g == 12, @gval == nil and g.class == Fixnum
I realize that this has to do with the way Ruby processes undefined
identifiers at runtime. However, it strikes me that it is fundamentally
wrong to ignore an existing explicit method declaration within the
current scope in favour of creating a locally scoped variable instead.
This behaviour is counter-intuitive and the ugly work-around required
(self.g = 12) only accentuates how out of place it is.
I presume that there exists a strong reason why this construct remains
in the language. However, I have not been able to find an explanation
as to why this behaviour is desired so if someone here could inform me
as to why it is retained then I would be much obliged.
def g=( value )
@gval = value.to_s
end
def g
@gval
end
g = 12
Then g == 12, @gval == nil and g.class == Fixnum
I realize that this has to do with the way Ruby processes undefined
identifiers at runtime. However, it strikes me that it is fundamentally
wrong to ignore an existing explicit method declaration within the
current scope in favour of creating a locally scoped variable instead.
This behaviour is counter-intuitive and the ugly work-around required
(self.g = 12) only accentuates how out of place it is.
I presume that there exists a strong reason why this construct remains
in the language. However, I have not been able to find an explanation
as to why this behaviour is desired so if someone here could inform me
as to why it is retained then I would be much obliged.