Skip to content

Instantly share code, notes, and snippets.

@june29
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/8709992 to your computer and use it in GitHub Desktop.
Save june29/8709992 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require "date"
class Date
(1..5).each { |n|
define_method("第#{n}?") { (self.day.to_f / 7.to_f).ceil == n }
}
%w(日 月 火 水 木 金 土).each_with_index { |曜日, index|
define_method("#{曜日}曜日?") { self.wday == index }
}
end
明日 = Date.today + 1
targets = []
targets << "可燃ごみ" if 明日.火曜日? or 明日.金曜日?
targets << "資源ごみ" if 明日.木曜日?
targets << "不燃ごみ" if 明日.水曜日? and (明日.第1? or 明日.第3?)
message =
if targets.empty?
"明日に回収されるごみはありません。"
else
"明日は%sの日です。" % targets.map { |target| "「#{target}」" }.join
end
puts message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment