Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
friday
communitycreator

How to check if today is Friday in Ruby

okwudili onyejiaku

Overview

We can check if today is Friday in Ruby when you call the friday? method on a time object. It returns a Boolean value. true is returned if today is Friday. Otherwise, false is returned.

Syntax

t_o.friday?
Syntax to check if today is Friday in Ruby

Parameters

t_o: this is the time object. This time object can be created in many ways.

Return value

The value returned is a Boolean value. It returns true if the day or the time represents Friday.

Code example

# create time objects
t1 = Time.now
t2 = Time.new(2020)
t3 = Time.new(1987, 12, 18) # friday December, 1987

# check if Friday 
# and print result
puts t1.friday?
puts t2.friday?
puts t3.friday?
Check if time is Friday in Ruby

Explanation

  • Line 2 and 3: We create two time objects.
  • Line 3: We create an actual time that is Friday.
  • Line 8-10: We check if the time objects are Friday and print their results.

RELATED TAGS

ruby
friday
communitycreator
RELATED COURSES

View all Courses

Keep Exploring