我脑子里放了个屁,没有看相关的问题部分。
我的答案已经找到了。
(是的,我是 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
这是我的week.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
问题可能只是一些愚蠢的命名错误,但如果是的话,我还没有找到。