require files namespace!

K

Krishna Rokhale

Hi,

this seems to be bugging me for a bit now.

I am creating a gem with tool.rb in the /lib folder

module Tool

require 'tool/word.rb'
require 'tool/sentence.rb'

end

and the word.rb is

class Tool::Word

def methods........

end

and sentence.rb is

class Tool::Sentence

def methods.......

end


and i am using irb
NameError: undefined local variable or method `tool' for main:Object
from (irb):1

I am not sure how to include the files!

I appreciate your help.
Thanks!
 
R

Roger Pack

NameError: undefined local variable or method `tool' for main:Object
from (irb):1

I am not sure how to include the files!

What's the full backtrace? (chances are you have a stray "tool" in there
somewhere)
 
B

Brian Candler

Roger said:
What's the full backtrace? (chances are you have a stray "tool" in there
somewhere)

Yes, it's saying that you're using "tool" (lower-case t) by itself.

If I take just the code you posted, then it works fine for me under
ruby-1.8.7 and Ubuntu Karmic:

$ ls -lR
:
total 4
drwxr-xr-x 3 brian brian 4096 2010-01-27 07:45 lib

/lib:
total 8
drwxr-xr-x 2 brian brian 4096 2010-01-27 07:45 tool
-rw-r--r-- 1 brian brian 68 2010-01-27 07:44 tool.rb

/lib/tool:
total 8
-rw-r--r-- 1 brian brian 25 2010-01-27 07:44 sentence.rb
-rw-r--r-- 1 brian brian 21 2010-01-27 07:44 word.rb

$ head $(find . -type f)
==> ./lib/tool/word.rb <==
class Tool::Word
end

==> ./lib/tool/sentence.rb <==
class Tool::Sentence
end

==> ./lib/tool.rb <==
module Tool

require 'tool/word.rb'
require 'tool/sentence.rb'

end

$ irb -Ilib --simple-prompt
(However, note that it is preferred if you require 'tool' rather than
require 'tool.rb')
 
K

Krishna Rokhale

Thanks Brian and Roger!

Well, this one was weird, i checked out for a missing or extra tool and
did not seem to find anything odd.

I simply quit the terminal and restarted it, and it worked like a charm,
yeah sometimes it just works that way.

Thanks anyway though!!
 

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

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top