# Undefined local variable or method \`code\_words' for main:Ob

**URL:** <https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116>\
**Category:** Ruby\
**Created:** [July 5, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116 "2010-07-05T21:31:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 5, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116/1 "2010-07-05T21:31:31Z")

</div>

I have the problem:

undefined local variable or method `code\_words’ for main:Ob

I’m trying to work on an example from the Why’s poignant guide to Ruby,  
and don’t know why I’m getting the preceding error.

I just made some small changes in the example, and they are not related  
to the syntax, just the fill outs.

The first .rb is “wordlist.erb”: [http://pastie.org/1031629](http://pastie.org/1031629)

The second one, “idea.rb”: [http://pastie.org/1031631](http://pastie.org/1031631)

Provided that the Ruby version I’m using is: ruby 1.8.6

So, any idea how I can workaround this issue?

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 5, 2010, 9:33pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116/2 "2010-07-05T21:33:01Z")

</div>

Abder-rahman Ali wrote:

> I have the problem:
> 
> undefined local variable or method `code\_words’ for main:Ob
> 
> I’m trying to work on an example from the Why’s poignant guide to Ruby,  
> and don’t know why I’m getting the preceding error.
> 
> I just made some small changes in the example, and they are not related  
> to the syntax, just the fill outs.
> 
> The first .rb is “wordlist.erb”: [http://pastie.org/1031629](http://pastie.org/1031629)
> 
> The second one, “idea.rb”: [http://pastie.org/1031631](http://pastie.org/1031631)
> 
> Provided that the Ruby version I’m using is: ruby 1.8.6
> 
> So, any idea how I can workaround this issue?
> 
> Thanks.

Please omit the last comma in wordlist.rb. But, I’m still having the  
problem. Appreciate your collaboration.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 6, 2010, 9:26am UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116/3 "2010-07-06T09:26:29Z")

</div>

On Mon, Jul 5, 2010 at 9:31 PM, Abder-rahman Ali  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The first .rb is “wordlist.erb”: [http://pastie.org/1031629](http://pastie.org/1031629)
> 
> The second one, “idea.rb”: [http://pastie.org/1031631](http://pastie.org/1031631)
> 
> Provided that the Ruby version I’m using is: ruby 1.8.6
> 
> So, any idea how I can workaround this issue?

Local variables are not visible outside of the file they are created.  
You will to make code\_words a global variable ($code\_words) or a  
constant (CODE\_WORDS). I think for an example like this one those are  
the two simplest ways.

Jesus.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 6, 2010, 1:18pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-or-method-code-words-for-main-ob/191116/4 "2010-07-06T13:18:27Z")

</div>

JesÃºs Gabriel y GalÃ¡n wrote:

> On Mon, Jul 5, 2010 at 9:31 PM, Abder-rahman Ali  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The first .rb is “wordlist.erb”: [http://pastie.org/1031629](http://pastie.org/1031629)
> > 
> > The second one, “idea.rb”: [http://pastie.org/1031631](http://pastie.org/1031631)
> > 
> > Provided that the Ruby version I’m using is: ruby 1.8.6
> > 
> > So, any idea how I can workaround this issue?
> 
> Local variables are not visible outside of the file they are created.  
> You will to make code\_words a global variable ($code\_words) or a  
> constant (CODE\_WORDS). I think for an example like this one those are  
> the two simplest ways.
> 
> Jesus.

Thanks a lot. It worked 🙂

Really nice solutions.
