我在百分鐘網站在做的Ruby和部分過程中遇到的問題5.紅寶石在100分鐘,good_morning方法
我被要求創建一個good_morning
方法將打印出這樣的問候如'Happy Monday, it's the 130 day of 2013'
。這是我目前的計劃:
class PersonalChef
def good_morning
date = Time.new
today = Time("%A")
day_of_year = Time.yday
this_year = Time("%Y")
puts "Happy " + "#{today}" + "! It is the " + "#{day_of_year}" + " day of the year" + "#{this_year}"
return self
end
def make_toast(color)
puts "Making your toast #{color}!"
return self
end
def make_milkshake(flavor)
puts "Don\'t worry boss, my #{flavor} milkshake brings all the boys to the yard!"
return self
end
def make_eggs(quantity)
puts "Making you #{quantity} eggs sir!"
return self
end
end
但是當我通過IRB(load 'personal_chef.rb', frank = PersonalChef.new, frank.make_milkshake('chocolate')
等運行程序,一切工作正常,直到我嘗試鍵入frank.good_morning
到IRB,它提供了以下錯誤消息
"NoMethodError: undefined method
Time' for #<PersonalChef:0x00000001b61808> from personal_chef.rb:4:in
good_morning' from (irb):3 from /usr/bin/irb:12:in `'
我試過用Date
的方法代替Time
,仍然遇到同樣的問題。
感謝您的閱讀,希望對您即將提供的有用建議! e是更多有助於解決此問題的信息,請讓我知道。
非常感謝你雷!你達'B! – user2328042