开发者

Including Modules in Ruby

I am trying to include a Ruby module.

In the file helper.r开发者_运维问答b, I have this text

module Helper
...
end

In the file test.rb, I have this text:

....
require 'helper'
...

These files are on the same level of the directory yet I keep getting this error:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- helper (LoadError)
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from test.rb:4:in `<main>'

I have also tried

include Helper

in test.rb and get this error:

test.rb:4:in `<main>': uninitialized constant Object::Helper (NameError)

What am I doing wrong?


In Ruby 1.9 you should use

require_relative 'helper'


Try require './helper'. That should do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜