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

monday_of_this_week1.rb

This Ruby code snippet demonstrates how to create a variable for the current day and another variable for the next Monday from the current date using the Date class in Ruby. The today variable is set to the current date using the Date.today method, and the this_monday variable is set to the previous Monday by subtracting the number of days until the next Monday (which is equal to 1) from the current day.

For example, if today is a Thursday, then today would be set to “Thursday, February 25, 2022” and this_monday would be set to “Monday, February 28, 2022”.

Ruby code snippet

require 'date'
#=> true

today = Date.today
#=> #<Date: 2025-06-27 ((2460854j,0s,0n),+0s,2299161j)>
this_monday = today - today.wday + 1
#=> #<Date: 2025-06-23 ((2460850j,0s,0n),+0s,2299161j)>

Executed with Ruby 3.4.4.