I used windows cmd instead of eclipse IDE. I'll show the steps I used to find the errors for the code and finally fix them. DLTK plugin is not at fault here. Module file and test script are in the same folder.
LESSON - Module name and constant name in modules MUST begin with capital letter. Why, I don't know.
aModule.rb
module aModule
aConstant = 7
end
Test.rb
require 'aModule'
puts aModule::aConstant
cmd: cd into Test.rb folder and ruby Test.rb
error: ``require': cannot load such file -- tokenizer.rb (LoadError)`
help: Ruby 'require' error: cannot load such file
Ruby 1.9 has removed the current directory from the load path, and so
you will need to do a relative require on this file, as Pascal says:
require './tokenizer'
There's no need to suffix it with .rb, as Ruby's smart enough to know
that's what you mean anyway.
I made the following changes:
Test.rb
require './aModule'
puts aModule::aConstant
cmd: ruby Test.rb
error: class/module name must be CONSTANT (SyntaxError)
in aModule.rb
help: NameError in Ruby
I made the following changes:
aModule.rb
module AModule # capital
aConstant = 7
end
Test.rb
require './AModule'
puts AModule::aConstant
cmd: ruby Test.rb
error: undefined method 'aConstant' for AModule:Module (NoMethodError)
help: Used the above link. I think constant must also be named with capital.
Final working code:
aModule.rb
module AModule # capital
AConstant = 7 # capital
end
Test.rb
require './AModule'
puts AModule::AConstant
WTF is Ruby like this ??? And why the hell do I need to append ./
before a module name when it is in the same folder as the test script ?