
Submitted by chneukirchen (Tue May 11 16:05:45 UTC 2004)
This new way of constant lookup is confusing and didn't do what was promised, therefore it should be reverted.
class Foo
A = 1
end
def foo(&block)
f = Foo.new f.instance_eval(&block)
end
foo do
p self #=> #<Foo:0x4027f568> p self.class::A #=> 1 p A #=> 1 on 1.6.7; NameError on 1.6.8 and more recent.
end
This is especially in combination with instance_eval very confusing:
Object.new.instance_eval { B = 1; p B }
won't work.
This static behavior isn't something that's natural in a dynamic language and inconsistent as all other name are looked up dynamically.
However, a large part of rubyists thinks its much more confusing and surprising, therefore claim 1, "readability" was not reached. Matz himself admitted in ruby-talk:60270 that the proclaimed performance boost is "Currently none; not much in the future."
The change could break code depending on the way of constant lookup.
However, it is not possible to implement this change in pure Ruby without a change to the interpreter.

| Comments | Current voting | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|


RCRchive copyright © David Alan Black, 2003-2005.
Powered by .