# A.module\_eval question

**URL:** <https://www.ruby-forum.com/t/a-module-eval-question/181431>\
**Category:** Ruby\
**Created:** [January 11, 2010, 9:42pm UTC](https://www.ruby-forum.com/t/a-module-eval-question/181431 "2010-01-11T21:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [January 11, 2010, 9:42pm UTC](https://www.ruby-forum.com/t/a-module-eval-question/181431/1 "2010-01-11T21:42:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [January 12, 2010, 8:15am UTC](https://www.ruby-forum.com/t/a-module-eval-question/181431/2 "2010-01-12T08:15:58Z")

</div>

On 11.01.2010 21:42, Aryk G. wrote:

> 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](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/354034)

Kind regards

robert
