我大脑放屁并没有查看相关的问题部分。
我的答案已经找到。
(是的,我是Ruby的新手。)
这是我的控制台输出的内容:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- Week (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from main.rb:14:in `<main>'
这是我的main.rb
文件:
require 'week.rb'
class Decade
include Week
no_of_yrs = 10
def no_of_months
puts Week::FIRST_DAY
number = 10 * 12
puts number
end
end
d1 = Decade.new
puts Week::FIRST_DAY
Week.weeks_in_month
Week.weeks_in_year
d1.no_of_months
这是我的周刊.rb:
module Week
FIRST_DAY = "Sunday"
def Week.weeks_in_month
puts "You have four weeks in a month"
end
def Week.weeks_in_year
puts "You have 52 weeks in a year"
end
end
问题可能只是一些愚蠢的命名错误,但如果是的话我还没找到。
答案 0 :(得分:2)
Ruby在$LOAD_PATH
环境变量中找到的目录中查找您的require模块。如果它不在那里,它会发出尖叫声。您可以做几件不同的事情来解决它:
require './weeks.rb'
weeks.rb
移至已经在LOAD_PATH 答案 1 :(得分:1)
require_relative 'week.rb'
也应该有用。