From fb7ee36275030fc7d9b53726e15c03ab418af9f5 Mon Sep 17 00:00:00 2001 From: Rikuoh Date: Fri, 8 Mar 2024 22:33:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=B2=E3=81=A8=E3=81=BE=E3=81=9A=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cal.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cal.rb b/cal.rb index 0ba865e..e9de621 100755 --- a/cal.rb +++ b/cal.rb @@ -3,21 +3,19 @@ require 'date' require 'optparse' -optmonth = ARGV.getopts('m:') -optyear = ARGV.getopts('y:') - -# opt = OptionParser.new -# opt.on('-m') -# opt.on('-y') -# opt.parse! - year = Date.today.year month = Date.today.month + +opt = OptionParser.new +opt.on('-m int') { |v| month = v.to_i } +opt.on('-y int') { |v| year = v.to_i } +opt.parse!(ARGV) + startwday = Date.new(year, month, 1).wday # その月の最初の曜日 enddate = Date.new(year, month, -1).day # その月の最後の曜日 week = %w[日 月 火 水 木 金 土] -puts "\t#{month}月 #{year}" +puts month.to_s.rjust(8) + '月 ' + year.to_s puts week.join(' ') print ' ' * startwday