我在 JumpStart 实验室网站上花了 100 分钟完成了 Ruby,在第 5 部分中遇到了问题。
我被要求创建一个 good_morning 方法来打印诸如“周一快乐,2013 年第 130 天”之类的问候语。这是我目前的程序:
class PersonalChef
def good_morning
today = Date.today.strftime("%A")
day_of_year = Date.today.yday
puts "Happy#{today}! It is the #{day_of_year} day of year."
return self
end
def make_toast(color)
puts " Making your toast #{color}!"
return self
end
def make_milkshake(flavor)
puts " Making a #{flavor} milkshake!"
return self
end
def make_eggs(quantity)
puts " Making you #{quantity} eggs!"
return self
end
end
当我尝试在 irb('personal_chef.rb', frank = PersonalChef.new, frank.make_milkshake('chocolate') 等上运行程序加载时,一切正常,直到我尝试将 frank.good_morning 输入到 irb 中,这给出了以下错误消息:
NameError: **uninitialized constant** PersonalChef :: Date
from personal_chef.rb:5: in good_morning from (irb):3 from /bin/irb:12:in '<main>'
任何帮助我解决此问题的帮助或信息将不胜感激。谢谢你的时间!