Heads up: This description was created by AI and might not be 100% accurate.

monday_of_this_week1.rb

This Ruby code snippet demonstrates date manipulation. It first requires the date library. Then, it gets the current date. Finally, it calculates the date of the previous Monday from the current date by subtracting the current day of the week (wday) from the current date and adding 1.

Ruby code snippet

require 'date'
#=> true

today = Date.today
#=> #<Date: 2025-07-22 ((2460879j,0s,0n),+0s,2299161j)>
this_monday = today - today.wday + 1
#=> #<Date: 2025-07-21 ((2460878j,0s,0n),+0s,2299161j)>

Executed with Ruby 3.4.5.