# Uninitialized constant error with a variables within a module

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-error-with-a-variables-within-a-module/233290>\
**Category:** Rails\
**Created:** [December 1, 2014, 3:09pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-error-with-a-variables-within-a-module/233290 "2014-12-01T15:09:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [December 1, 2014, 3:09pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-error-with-a-variables-within-a-module/233290/1 "2014-12-01T15:09:18Z")

</div>

Hi,

New to ruby development so wondering if someone could help…

I have this code in a file1.rb

#file1.rb

module GG  
class GG

::NAME = ‘gginfrausermanager’

```
end

```

end

and want to call this variable in another file2.rb with the following  
code:

#file2.rb

require ‘./file1.rb’  
include GG

p “#{GG::NAME} is called from file1.rb”

However when I do a ruby file2.rb I get uninitialized constant GG::NAME.

Can you tell me what I’m doing wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![trekr67](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@trekr67](https://www.ruby-forum.com/u/trekr67)\
**Post date:** [December 1, 2014, 11:02pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-error-with-a-variables-within-a-module/233290/2 "2014-12-01T23:02:23Z")

</div>

On Monday, December 1, 2014 2:07:58 PM UTC, trekr67 wrote:  
[snip]

> ::NAME = ‘gginfrausermanager’

[snip]

> Can you tell me what I’m doing wrong?

There are two things here. First, because you’ve done ::NAME = (instead  
of  
NAME=) this has set the constant at the top level: you’ve created  
Object::NAME, not GG::GG::NAME

The second thing is that constant lookup always looks at the current  
scoping before it starts walking up the lexical scope chain or the  
ancestry  
chain: even after you include GG, GG::NAME is referring to the top level  
GG  
(i.e. the module not the class)

Fred

---

<div class="post-metadata">

**Author:** ![trekr67](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@trekr67](https://www.ruby-forum.com/u/trekr67)\
**Post date:** [December 6, 2014, 6:24pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-error-with-a-variables-within-a-module/233290/3 "2014-12-06T18:24:59Z")

</div>

What exactly are you trying to achieve???
