Conversation
| else | ||
| print "\n" | ||
| end | ||
| end No newline at end of file |
| require 'optparse' | ||
|
|
||
| # 今日の日付を取得する | ||
| today_date = Date.today |
|
|
||
| # 今日の日付を取得する | ||
| today_date = Date.today | ||
| date_params = {year: today_date.year, month: today_date.month, day: today_date.day} |
| require 'date' | ||
| require 'optparse' | ||
|
|
||
| # 今日の日付を取得する |
There was a problem hiding this comment.
説明的なコメントは原則なくしたいですね。
参考
https://qiita.com/jnchito/items/f0d90af4ed44b7484103
| opt.on('-y [VAL]') {|v| v.to_i} | ||
| opt.on('-m [VAL]') {|v| v.to_i} | ||
|
|
||
| opt.parse!(ARGV, into: cmd_params) |
| else | ||
| date_params[:month] = cmd_params[:m] | ||
| end | ||
| end |
There was a problem hiding this comment.
後述してますが、今日の判定を見直すとsame_ymなくせそうですね。するとこの辺のロジックもすっきりしそうだな、と思います。
| #色の反転 | ||
| def reverse_cmpcolor(text) | ||
| "\e[7m#{text}\e[0m" | ||
| end |
There was a problem hiding this comment.
他のところメソッド化してないのにここだけ急にメソッドなことに違和感を感じます。なぜここだけメソッドなのですか?
|
|
||
| # カレンダー部分の出力 | ||
| # 余白部分の空白を予め出力しておく | ||
| dow_num = first_date.wday |
There was a problem hiding this comment.
dow_numがよくわからない命名だなと思いました。dowってなんですか? date of week? 一般的な略称なんでしょうか? あまり一般的でないなら変に省略すると可読性が下がるかな、と思います。
| # カレンダー部分の出力 | ||
| # 余白部分の空白を予め出力しておく | ||
| dow_num = first_date.wday | ||
| dow_num.times { print " " } |
| dow_num.times { print " " } | ||
|
|
||
| # 日にちの出力 | ||
| (first_date.day..last_date.day).each do |num| |
There was a problem hiding this comment.
ブロック変数にもっと具体的な名前をつけましょう。numではなんのnumなのかわからないですよね。
| if same_ym == true && num == date_params[:day] | ||
| print reverse_cmpcolor(num.to_s.rjust(2)) | ||
| (first_date..last_date).each do |current_date| | ||
| if current_date.year == date_params[:year] && current_date.month == date_params[:month] && current_date.day == date_params[:day] |
There was a problem hiding this comment.
today_dateせっかくあるのでうまく活用しましょうー。Date型同士で比較するとシンプルですね
| print current_date.day.to_s.rjust(2) | ||
| end | ||
| if dow_num == 6 | ||
| if day_of_week_index == 6 # 曜日リセット |
There was a problem hiding this comment.
https://docs.ruby-lang.org/ja/latest/method/Date/i/saturday=3f.html というのが全曜日分あったりします。このへんうまく使うとday_of_week_indexは無くせるのではないかな、と思いました。いかがでしょうか。
This reverts commit f340860.
|
|
||
| # 日にちの出力 | ||
| (first_date..last_date).each do |current_date| | ||
| if current_date.year == today_date.year && current_date.month == today_date.month && current_date.day == today_date.day |
There was a problem hiding this comment.
Date型同士っていうのはこういうことじゃないです。これだと年(Integer)、月(Integer), 日(Integer)それぞれで比較ですよね。
No description provided.