[Ruby] I want to make a program that displays today's day of the week!

Introduction

I am practicing writing programs to improve my thinking ability in programming. This time, I wrote a program that outputs today's day of the week using the "date" class.

Date class

You can use the Date class with the following description.

python


require "date"

If you want to get today's day of the week using the Date class

python


Date.today.wday

It is described as. wday is a method provided in the Date class that can get the day of the week as an integer from 0 (Sunday) to 6 (Saturday).

Using the above, output today's day of the week in sentences. I tried it as follows.

python


require "date"

day = Date.today.wday
days = ["Day","Moon","fire","water","wood","Money","soil"]

puts "today#{days[day]}It's the day of the week"

By defining the array days, the strings were stored from Sunday (0) to Saturday (6).

Recommended Posts

[Ruby] I want to make a program that displays today's day of the week!
I want to output the day of the week
How to get today's day of the week
[Ruby] Code to display the day of the week
I want to make a specific model of ActiveRecord ReadOnly
[Ruby] Display today's day of the week using Date class
[Ruby] I want to reverse the order of the hash table
The story of Collectors.groupingBy that I want to keep for posterity
I want to change the value of Attribute in Selenium of Ruby
I tried to make a parent class of a value object in Ruby
[Ruby] I want to extract only the value of the hash and only the key
I tried to make full use of the CPU core in Ruby
Make a margin to the left of the TextField
[Ruby] I want to do a method jump!
I want to var_dump the contents of the intent
I want to get the value in Ruby
I want to graph the number of photo AC downloads [MySQL ring cooperation] ~ Coding 10 lines a day ~
I tried to make a sample program using the problem of database specialist in Domain Driven Design
Rails6 I want to make an array of values with a check box
I want to recursively get the superclass and interface of a certain class
[Ruby] I want to make an array from a character string with the split method. And vice versa.
I tried to make a program that searches for the target class from the process that is overloaded with Java
I want to call a method of another class
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to add a delete function to the comment function
Rails The concept of view componentization of Rails that I want to convey to those who want to quit
[Rails] I want to display the link destination of link_to in a separate tab
Determine that the value is a multiple of 〇 in Ruby
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
I want to make a list with kotlin and java!
I want to call a method and count the number
I want to make a function with kotlin and java!
I want to create a form to select the [Rails] category
I tried to summarize the basic grammar of Ruby briefly
[Ruby] How to retrieve the contents of a double hash
I want to give a class name to the select attribute
I want to create a Parquet file even in Ruby
A program that counts the number of words in a List
I tried to make a client of RESAS-API in Java
I want to narrow down the display of docker ps
[ruby] Creating a program that responds only to specific conditions
I want to temporarily disable the swipe gesture of UIPageViewController
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
A memo of the program that allows you to realize that the probability of dice rolling is about 1/6
I want to get a list of the contents of a zip file and its uncompressed size
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
A collection of patterns that you want to be aware of so as not to complicate the code
I tried to solve the problem of "multi-stage selection" with Ruby
Ruby: I made a FizzBuzz program!
The story of making a binding for libui, a GUI library for Ruby that is easy to install
I want to create a chat screen for the Swift chat app!
I want to make a button with a line break with link_to [Note]
[Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)
I want to add a browsing function with ruby on rails
I want to understand the flow of Spring processing request parameters
I want to use swipeback on a screen that uses XLPagerTabStrip