[Ruby] [ruby] Creating a program that responds only to specific conditions

less than 1 minute read

Content

Write the code that displays today’s day of the week using the Date class. However, change the displayed content as follows only if it was Friday.

(Output content) “Today is Monday” “Today is Friday!!!”

Implementation

image.png image.png

Comment

Since we will handle dates in Ruby this time, we will use the Date class which is a library. Line 1 calls the Date class from the library. Using the wday method on the 3rd line, you can get today’s value when it is an integer from 0 (Sunday) to 6 (Saturday). *Because it is a value, only integers can be obtained. So, in the 4th line, enter the days of the week in an array for days. And if today’s date is 5 (Friday) in the if statements on lines 6-10 The expression that outputs “Today is Friday!!!” “Today is ○ day of the week” is output

Tags:

Updated: