From: Wilson Bilkovich Date: 2005-08-16T05:51:09+09:00 Subject: Re: Mixing Constants into objects On 8/15/05, Caleb Clausen wrote: > On 8/14/05, David A. Black wrote: > > On Mon, 15 Aug 2005, gabriele renzi wrote: > > > mh.. maybe "lexical" is the better word ? > > > > I think it's more than that. What I should have said was: constant > > references are resolved at parse-time, rather than run-time. At least > > I think that's the case. > > Just how constant lookups work is something of a mystery to me in some > cases... it's clearly less dynamic than method lookup, but it is > run-time lookup, not compile time: > > irb(main):001:0> class K > irb(main):002:1> Foo=1 > irb(main):003:1> end > => 1 > irb(main):004:0> def fk; K::Foo end > => nil > irb(main):005:0> fk > => 1 > irb(main):006:0> class K > irb(main):007:1> Foo=2 > irb(main):008:1> end > (irb):7: warning: already initialized constant Foo > => 2 > irb(main):009:0> fk > => 2 My (possibly totally off-base) understanding is that, as there is no 'compile' step in Ruby, the constants get 'burned' into the AST, as do things like regular expression literals, between forward-slashes. That would explain why they "look" like runtime evaluations, but they aren't the same kind of citizen as variables.