我用windows cmd代替了eclipse IDE。我将展示我用来查找代码错误的步骤,并最终修复它们。 DLTK插件在这里没有问题。模块文件和测试脚本位于同一个文件夹中。
LESSON -模块中的模块名称和常量名必须以大写字母开头。为什么,我不知道。
aModule.rb
module aModule
aConstant = 7
end
Test.rb
require 'aModule'
puts aModule::aConstant
CMD:光盘插入Test.rb文件夹和ruby Test.rb
错误:``需要“:无法加载这样的文件 - tokenizer.rb(LoadError)` 帮助: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.
我做了以下修改:
Test.rb
require './aModule'
puts aModule::aConstant
CMD:ruby Test.rb
错误:在aModule.rb 帮助:NameError in Ruby
我做了以下修改:
aModule.rb
module AModule # capital
aConstant = 7
end
Test.rb
require './AModule'
puts AModule::aConstant
CMD:红宝石测试。rb 错误:undefined method 'aConstant' for AModule:Module (NoMethodError)
帮助:使用上面的链接。我认为不变也必须以资本命名。
最后工作的代码:
aModule.rb
module AModule # capital
AConstant = 7 # capital
end
Test.rb
require './AModule'
puts AModule::AConstant
WTF是红宝石这样???以及为什么我需要在模块名称之前附加./
,因为它与测试脚本位于同一个文件夹中?
无法复制。 – sawa 2014-09-21 07:39:43
@sawa - 其实我已经定义了它。我在put中犯了一个小小写错误。我现在修好了。同样的错误依然存在。如果您在我的问题中看不到任何错误或缺点,您可以请我高举零点吗?谢谢。 – 2014-09-21 07:40:49
我的评论适用于编辑后的问题(我的删除答案适用于编辑前的问题)。我不会按照您的要求以任何方式进行投票。你不应该问这个问题。而且,正如我写的那样,它不能被复制。 – sawa 2014-09-21 07:42:44