1. Conclusion </ b>
2. What is the Date class? </ B>
3. How to write </ b>
4. What I learned from here </ b>
❶ "Date class" ❷ today method ❸wday method ❹ Array ❺ if statement
use!
"Date class" is included in the Ruby library This is a standard function! You need a "require" method to use these things.
Let's see how to actually program! This time, the tension will rise on Friday, which is ahead of Saturday and Sunday, so Let's make it "special wording only on Friday"! Also, make your holidays special.
Today's day of the week output
require"date" ❶
week = ["Day", "Month", "fire", "water", "wood", "Money", "soil"]❹
now_week_num = Date.today.wday❷❸
now_week_char = week[now_week_num]
(Since the subscript of the array is a variable in ❷❸, the subscript number changes every day of the week)
❺
if now_weekday_num == 5
puts "today#{now_week_char}Day of the week! ︎ You have no choice but to go drinking!!!"
elsif now_weekday_num == 6 || now_weekday_num == 0
puts "today#{now_week_char}It's a day of the week, come on a date ♪"
else
puts "Still today#{now_week_char}It's a day of the week ... When will the holidays come ..."
end
❶ Call the Date class ❷❸ Assign today's day of the week to the variable now_week_num ❹ An array that can output the day of the week as a subscript ❺ if elsif statement makes Friday and holidays special. Friday is equivalent to "5" in numbers.
In this way "Wording" depending on which day of the week "today" is You can change it!
This program often appears in games I thought that the story would change depending on the conversation options. It's more complicated, of course, but I think I've touched on the basics.
Recommended Posts