We use the sunday?
method to learn if today or a time object is Sunday or represents Sunday. The method returns a Boolean value true
or false
. If the time object is Sunday, true
is returned. Otherwise, false
.
t_o.sunday?
t_o
: This is the time object we want to check for representing Sunday.
The value returned is a Boolean value. If the time object is Sunday, true
will be returned. Otherwise, false
will be returned.
# create time objectst1 = Time.now # current timet2 = Time.new(1990)t3 = Time.new(1990, 4, 1) # sunday in 1998t4 = Time.new()# call the "sunday?" method# and print resultputs t1.sunday?puts t2.sunday?puts t3.sunday?puts t4.sunday?
Time.now
or the Time.new()
methods.sunday?
method to check if the time objects we create are actually Sunday or not. Then we printed the results.