Monday_of_this_week1.rb
This content was produced by an LLM and could include errors.
このスクリプトはDate版の週初め計算です。today.wday(0=日〜6=土)を使い today - today.wday + 1 で今週月曜日のDateオブジェクトを求めます。日曜日に実行した場合は翌日の月曜(ISO週の考え方)を指します。
require 'date'
#=> true
today = Date.today
#=> #<Date: 2026-08-22 ((2461275j,0s,0n),+0s,2299161j)>
this_monday = today - today.wday + 1
#=> #<Date: 2026-08-17 ((2461270j,0s,0n),+0s,2299161j)>
Ruby 4.0.6