[RUBY] Rails Tutorial Chapter 0: Preliminary Basic Knowledge Learning 5

Pre-basic knowledge learning: Ruby

PROGATE recommended in Rails Tutorial image.png

In the Rails tutorial, we have also prepared a course where you can learn the basic knowledge of the Web in Japanese in partnership with the programming learning service "Progate" for beginners. This service is especially suitable for people who have no programming experience because it does not require environment construction and allows you to experience coding on a browser. Of course, you can continue reading this tutorial as it is, but If you find it "difficult" to read, we recommend that you try to learn the basic knowledge in the course indicated by "Related" in the text. If you have little programming experience, we recommend starting with Progate's Ruby on Rails before reading the Rails tutorials. Quote: Rails Tutorial Chapter 1

Progate is a repetition of "read the explanation slide" ⇒ "write the code". I have used it, but it is very easy to understand and it is easy to challenge. It's definitely worth 980 yen a month.

However, personally, I recommend that you proceed to Chapter 4 first.

Maybe it ’s because I have learning experience, Of all the things I've learned so far, the Rails Tutorial Chapter 4 Rails-flavored Ruby was the easiest to understand. As was the case with Progate, When the concept of object-oriented comes out, it feels like (.´ ・ ω ・)? Why do you write this? I was wondering, but I couldn't help but remember the code and it was incomplete combustion. This time, I finally found out why I did the Rails Tutorial and wrote it in an object-oriented way.

Ruby basics

#STEP1:Display of character string|The string must be""(Double quotation)Or''(Single quote)Surround with|
puts ("Hello World") :Puts are automatically broken(I use this one more often)
print ("Hello World") :Print does not break.
#STEP2:Understanding variables 1|Variables are temporarily stored in a box|
a = "Hello World"
print(a) 
-> Hello World

#STEP3:Understanding variables 2|Of course, numbers are also included|
a = 3

#STEP4:Understanding variables 3|Only one can be stored & the last data entered is stored|
a = "Hello World"
a = "Hello Japan"
puts(a) 
-> Hello Japan

#STEP5:String manipulation| +Combine strings using|
a = "Hello"
b = "Japan"
puts(a + b) 
-> HelloJapan

puts(a +" "+ b) 
-> Hello Japan
#STEP6:Array 1|If you want to put multiple things, use an array|
a = ["Hello World", "Hello Asia", "Hello Japan"]
puts(a) 
-> ["Hello World", "Hello Asia", "Hello Japan"]

puts(a[0]) 
-> Hello World 

puts(a[1]) 
-> Hello Asia 

puts(a[2]) 
-> Hello Japan 

#STEP7:Array 2|Add things to the array|
a = [] #This makes an empty array
a.append("Hello World")
a.append("Hello Asia", "Hello Japan")
puts(a[0]) 
-> Hello World 

puts(a[1]) 
-> Hello Asia 

puts(a[2]) 
-> Hello Japan
#STEP8:hash|Named array|
user = { "name"=>"Michael Hartl","email"=>"[email protected]" }
puts(user)
-> { :name=>"Michael Hartl", :email=>"[email protected]" }

puts(user["name"]) 
-> "Michael Hartl"

puts(user["email"]) 
-> "[email protected]"

#STEP9:Hash 2|There is more than one notation ...|
user = { name:"Michael Hartl", email:"[email protected]" }

puts(user[:name]) 
-> "Michael Hartl"

puts(user[:email]) 
-> "[email protected]"

#STEP10:Combined hash and array technique|I often use it like a matryoshka doll|
user_data = []
user = { name:"Michael Hartl", email:"[email protected]" }

user_data.append(user)
puts(user_data) 
-> [{:name=>"Michael Hartl", :email=>"[email protected]"}]

user = { name:"Michael Jacson", email:"[email protected]" }
user_data.append(user)
puts(user_data) 
-> [{:name=>"Michael Hartl", :email=>"[email protected]"}
{:name=>"Michael Hartl", :email=>"[email protected]"}]

puts(user_data[0][:name]) 
-> "Michael Hartl" #In the 0th array"name"Take out
#STEP11 length method|Returns the number of characters / the number of contents in the array|
a = "length"
puts(a.length)
-> 6 #Returns the number of characters

user_data = [{ name:"Michael Hartl", email:"[email protected]" },
{ name:"Michael Hart", email:"[email protected]" },
{ name:"Michael Har", email:"[email protected]" },
{ name:"Michael Ha", email:"[email protected]" }]

puts(user_data.length)
-> 4 #Returns the number of hashes contained in the array
#STEP:Loop processing|Use each often|
user_data = [{ name:"Michael Hartl", email:"[email protected]" },
{ name:"Michael Hart", email:"[email protected]" },
{ name:"Michael Har", email:"[email protected]" },
{ name:"Michael Ha", email:"[email protected]" }]

user_data.each do |user| 
  puts("name: " user[:name] + "mail address: " + user[:email])
->name:Michael Hartl Email Address: [email protected]
->name:Michael Hart Email Address: [email protected]
->name:Micheal Har Email Address: [email protected]
->name:Micheal Ha Email Address: [email protected]

#Let's understand the contents of the process(^_-)-☆
1 user_The first line of data|user|Store in the variable user defined in
  #user = { name:"Michael Hartl", email:"[email protected]" }Enters.
2 puts("name: " user[:name] + "mail address: " + user[:email])Shaped and displayed
  #name:Michael Hartl Email Address: [email protected]
3 .Each is a method that repeats until there are no more arrays

for sentence ...? while statement ...? I don't see much. Someone has created an each method using a for statement or the like. When I learned programming when I was a student, I used a for statement to describe the process of extracting one by one. It's convenient thanks to each method, but you can't see the actual processing content, right? I think this is the cause of the haze. On the other hand, if you can understand complicated processing (^ ω ^) ... Since the processing is complicated, I'm really grateful that it can be used quickly with convenient methods.

Digression: I also challenged Progate a few years ago.

Progate is a repetition of "read the explanation slide" ⇒ "write the code". It's very easy to understand, so I thought it was worth 980 yen a month. What I learned with Progate is HTML / CSS / Python / JavaScript / jQuery.

After studying at Progate, you will learn how to write code. You will reach a level where you can create a static website or a website with a little movement.

Nice single page site 1 that can be used as a reference for design If you really do your best, you can create a nice static website.

Even so, there are some parts that are not knowledgeable if only Progate is used.

  • How do you publish your website to the internet?
  • How do you get your own domain like qiita.com?
  • How to embed Google Map on your website?
  • What should I do if I want to create a web application linked with a database?

When I tried to make something, I didn't have enough knowledge ... There is a lot of information, so what should I do to make it chaotic? That's right. I think the best environment is one where you can listen to people who are familiar with what you want to make.

Recommended Posts

Rails Tutorial Chapter 0: Preliminary Basic Knowledge Learning 5
Rails Tutorial Chapter 3 Learning
Rails Tutorial Chapter 4 Learning
Rails Tutorial Chapter 1 Learning
Rails Tutorial Chapter 2 Learning
rails tutorial Chapter 6
rails tutorial Chapter 1
rails tutorial Chapter 5
rails tutorial Chapter 10
rails tutorial Chapter 9
rails tutorial Chapter 8
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 7
Rails Tutorial 6th Edition Learning Summary Chapter 4
Rails Tutorial 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial 6th Edition Learning Summary Chapter 3
Rails Tutorial 6th Edition Learning Summary Chapter 8
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
[Rails] Learning with Rails tutorial
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 8 Notes
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
Ruby on Rails basic learning ①
[Rails Tutorial Chapter 4] Rails-flavored Ruby
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
Basic knowledge of Ruby on Rails
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
Chewing Rails Tutorial [Chapter 2 Toy Application]
Rails Tutorial (4th Edition) Memo Chapter 6
rails tutorial
Basic knowledge
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
Rails tutorial test
Summary of basic knowledge of Rails acquired by progate
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3
Rails tutorial memorandum 1
Rails learning day 3
Rails tutorial memorandum 2
Java basic knowledge 1
Rails learning day 4
Rails learning day 2
Chewing Rails Tutorial [Chapter 3 Creating Almost Static Pages]
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
Rails basic philosophy
Start Rails Tutorial
[Beginner] Rails Tutorial
rails learning day 1
Resolve Gem :: FilePermissionError when running gem install rails (Rails Tutorial Chapter 1)