C
Christophe Poucet
Hello,
I've noticed the following behaviour and I'm not certain if this is
expected behaviour, however from the point of view of any other
language, it certainly seems odd.
Assume there is no constant with the name 'X' defined anywhere.
X => NameError: uninitialized constant X
proc{|X| true}.call(15) => true
X => 15
proc{|X| true}.call(15) # true, warning: already initialized constant
X
I would presume that the X would be localized to the proc. I know that
for normal variables, the variable in the calling scope is only changed
if it already exists, but in this case, the constant X does not even
exist. (And when it does exist, is it really preferred behaviour that a
proc will change a constant?)
With regards,
Christophe
I've noticed the following behaviour and I'm not certain if this is
expected behaviour, however from the point of view of any other
language, it certainly seems odd.
Assume there is no constant with the name 'X' defined anywhere.
X => NameError: uninitialized constant X
proc{|X| true}.call(15) => true
X => 15
proc{|X| true}.call(15) # true, warning: already initialized constant
X
I would presume that the X would be localized to the proc. I know that
for normal variables, the variable in the calling scope is only changed
if it already exists, but in this case, the constant X does not even
exist. (And when it does exist, is it really preferred behaviour that a
proc will change a constant?)
With regards,
Christophe