monday_of_this_week2.rb(date)
This Ruby snippet captures the current date and time, then calculates and assigns the date of the most recent Monday by subtracting the number of seconds corresponding to the days elapsed since the beginning of the week.
Execution:
today = Time.now
#=> 2024-12-08 04:08:11.264750487 +0000
this_monday = today - (today.wday - 1) * 24 * 60 * 60
#=> 2024-12-09 04:08:11.264750487 +0000
Executed with Ruby 3.3.6