undefined local variable or method `code_words' for main:Ob

  • Thread starter Abder-rahman Ali
  • Start date
A

Abder-rahman Ali

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

The second one, "idea.rb": 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.
 
A

Abder-rahman Ali

Abder-rahman Ali said:
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

The second one, "idea.rb": 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.
 
J

Jesús Gabriel y Galán

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

The second one, "idea.rb": 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.
 
A

Abder-rahman Ali

Jesús Gabriel y Galán said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top