advenk
1
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
require ‘tool.rb’
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!
advenk
2
require ‘tool.rb’
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)
advenk
3
Roger P. wrote:
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
require ‘tool.rb’
=> true
(However, note that it is preferred if you require ‘tool’ rather than
require ‘tool.rb’)
advenk
4
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!!