From: Robert Klemme Date: 2010-01-12T16:15:12+09:00 Subject: Re: A.module_eval question On 11.01.2010 21:42, Aryk Grosz wrote: > I'm having trouble understanding why this is: > > module A > module B > end > end > > A.module_eval "B" -> A::B > A.module_eval do B end -> ERROR! > A.module_eval do self::B end => A::B > > Why does the second one error out? If its actually being evaluated > within the scope of the module, it should work...no? > > > Could someone explain this to me. Is there a trick I'm not doing? What version of Ruby did you use? IIRC in 1.8 versions the lookup of the constant was statically scoped so - since there is no B around - you get an error. With the other approaches you explicitly start the lookup at module A. We had a recent discussion about this where I collected some links about the topic: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/354034 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/