Although I was enthusiastic about "Let's learn programming !!" Programming seems to be difficult, I can't read English, I'm not good at PC operation itself, For you who were frustrated a long time ago __ Read this article ・ Just move your PC and you will see "What! Programming is interesting!" The purpose is to make you think. __
I would like to serialize it under the title of Programming Encyclopedia.
First of all, although it is the completed form this time, the following contents can be confirmed on the terminal.
$ ruby review.rb #If the following content is displayed, it is successful.
Genre:Cartoon
---------------------------
title:one piece
---------------------------
Impressions:
National cartoon.
I can't wait for the weekly serialization.
Foreshadowing is amazing!
---------------------------
Backslash notation is a notation that starts with ** \ (backslash) **. The following usage is possible.
notation | meaning |
---|---|
\n | new line |
\t | tab |
\b | Backspace |
\ \ | backslash |
The backslash notation is described in "" (double quotation marks)!
This is a description example of \ n.
puts "① The city of Japan is Tokyo. The capital of England is London"
puts "② The city of Japan is Tokyo.\n The capital of England is London"
You can check it in the terminal as follows.
① The city of Japan is Tokyo. The capital of England is London
② The city of Japan is Tokyo.
The capital of England is London
Let's proceed with the implementation in earnest using \ n!
First, use the puts method to represent the completed form.
review.rb
puts "Genre" + ":" + "Cartoon"
puts "---------------------------"
puts "title" + ":" + "one piece"
puts "---------------------------"
puts "Impressions" + ":\n"
puts "National cartoon.\n\n"
puts "I can't wait for the weekly serialization.\n\n"
puts "Foreshadowing is amazing!\n"
puts "---------------------------"
$ ruby review.rb #If it is written as follows, it is successful.
Genre:Cartoon
---------------------------
title:one piece
---------------------------
Impressions:
National cartoon.
I can't wait for the weekly serialization.
Foreshadowing is amazing!
---------------------------
However, this source code uses a lot of puts methods and remains very ugly. Let's make it easier to read by using the variables learned last time!
Describe using variables as follows.
review.rb
#variable
genre = "Cartoon"
title = "one piece"
review = "National cartoon.\n\n I can't wait for the weekly serialization.\n\n Foreshadowing is amazing!"
line = "---------------------------"
puts "Genre" + ":" + genre
puts line
puts "title" + ":" + title
puts line
puts "Impressions" + ":\n"
puts review
puts line
Up to this point, character concatenation has been written using +, but You can use ** Expression Expansion ** to organize them more neatly.
You can use an expression in a string and include it in the string obtained by the expression. It is written in ** # {expression} **.
Don't forget to write ** "" (double quotes) when expanding expressions. ** **
This is a description example of expression expansion.
num = "5"
city = "Tokyo"
puts "3 +The answer to 2 is#{num}is"
puts "The capital of the book#{city}is"
In the terminal, it will be displayed as follows.
3 +2's answer is 5
The capital of the book is Tokyo
Let's rewrite review.rb!
review.rb
#variable
genre = "Cartoon"
title = "one piece"
review = "National cartoon.\n\n I can't wait for the weekly serialization.\n\n Foreshadowing is amazing!"
line = "---------------------------"
puts "Genre: #{genre}\n#{line}"
puts "title: #{title}\n#{line}"
puts "Impressions: \n#{review}\n#{line}"
that's all! It's much more concise than the first code.
─────────────────────────────── ■ Books recommended by the author ───────────────────────────────
"Introduction to Web Technology to Become a Professional"
"How to think about changing jobs"
"High power marketing"
"Courage to be disliked"
"Complete output"
─────────────────────────────── ■ Movies recommended by the author ───────────────────────────────
"My Intern"
"Shin Godzilla"
"Dragon Ball Super Broly"
「School of Roc」
Recommended Posts