Caleb Clausen wrote: > On 8/14/05, David A. Black <dblack / wobblini.net> 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 > Constant binding is normally static: class K Foo=1 end def fk; K::Foo end fk class K Foo=2 end p fk # ==> 2 module M class K Foo=3 end p fk # ==> 2 p K::Foo # ==> 3 end # However, you can force dynamic constant binding: def sfk; self::K::Foo; end module M p sfk # ==> 3 end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407