find the current date in ruby

To find the current date in Ruby, you can use the Date class from the standard library. Here are a few ways to do it:

main.rb
require 'date'

# Option 1: Use Date.today
today = Date.today
puts today

# Option 2: Use Time.now and convert to Date
today = Time.now.to_date
puts today

# Option 3: Use Time.now and format as a string
today = Time.now.strftime("%Y-%m-%d")
puts today
253 chars
14 lines

All of these options will give you the current date in the format of YYYY-MM-DD. You can adjust the formatting to get the output you need.

gistlibby LogSnag