Skip to content

Commit

Permalink
refs #9 コマンドラインオプションで年、月が指定されなかった場合は、現在の年月を表示する
Browse files Browse the repository at this point in the history
標準添付ライブラリDateを使用して、現在の年月を取得
  • Loading branch information
asya81 committed Jun 20, 2022
1 parent 84dc946 commit 6865c11
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions 02.calendar/cal.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env ruby
require 'date'
require 'optparse'
# コマンドラインから受け取った年月
options = ARGV.getopts('y:', 'm:')
input_year = options["y"] # TODO: yオプションが指定されなかった場合の考慮が必要
input_month = options["m"] # TODO: mオプションが指定されなかった場合の考慮が必要
input_year, input_month = options["y"], options["m"]
# 現在の年月
today = Date.today
current_year, current_month = today.year, today.month
# コマンドラインからの指定がない場合、現在の年月を表示
year = input_year.nil? ? current_year : input_year
month = input_month.nil? ? current_month : input_month

puts(<<EOF)
#{input_month}#{input_year}
#{month}#{year}
日 月 火 水 木 金 土
1 2 3 4
5 6 7 8 9 10 11
Expand Down

0 comments on commit 6865c11

Please sign in to comment.