[Programming complete] §5 Create a review management app in Ruby

Purpose

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.

Development environment

Preparation

  1. Create a folder called "revew.rb" on your desktop.
  2. Launch VsVode and open revew.rb with "⌘ + O"

Completed form

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

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!

STEP1: Display characters on the screen

Notation using the puts method

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!

Notation using variables

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

Notation using expression expansion

Up to this point, character concatenation has been written using +, but You can use ** Expression Expansion ** to organize them more neatly.

Expression expansion

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.

Remarks

─────────────────────────────── ■ 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

[Programming complete] §5 Create a review management app in Ruby
Create a new app in Rails
Create a TODO app in Java 7 Create Header
Create a native extension of Ruby in Rust
Multiplication in a Ruby array
Create a fortune using Ruby
I want to create a Parquet file even in Ruby
Create and integrate Slack App and AWS Lambda (for ruby) in 30 minutes
I tried to create a simple map app in Android Studio
Create a database in a production environment
Implement a gRPC client in Ruby
What is a snippet in programming?
Create a Servlet program in Eclipse
[Complete programming] §3 Let's calculate using Ruby!
Try to create a server-client app
I thought about the best way to create a ValueObject in Ruby
I tried a calendar problem in Ruby
[Rails6] Create a new app with Rails [Beginner]
Try making a calculator app in Java
[Rails 5] Create a new app with Rails [Beginner]
[Portfolio] Bookmark management app [Ruby on Rails]
Beginners create portfolio in Ruby on Rails
Ruby Review 2
Create a Windows desktop application in Ruby and distribute an executable file (.exe)!
Ruby Review 1
Escape processing when creating a URL in Ruby
Create a simple search app with Spring Boot
Create a CSR with extended information in Java
Implement user management functions in a wizard format
Try to create a bulletin board in Java
Let's create a custom tab view in SwiftUI 2.0
Let's create a super-simple web framework in Java
I tried to create a LINE clone app
I made a Ruby extension library in C
How to create a theme in Liferay 7 / DXP
Create a tool for name identification in Salesforce
How to easily create a pull-down in Rails
(Ruby on Rails6) Creating data in a table
A certain programming classroom Ruby basic application function
Set up a webhook in Shopify's custom app
Docker command to create Rails project with a single blow in environment without Ruby