Ruby learning points (basic)

--Enclose the character string in quotation marks ('or "). Also, always describe the quotation marks in half-width characters.

--It is necessary to leave a half-width space after puts.

--Comment out by writing "#" at the beginning of the line

--Variables must be used only after the variables have been defined (variable name = value). (Because the program is executed in order from the top)

--Variable names can be decided freely, but there are some naming rules in Ruby. In particular, use an underscore (_) when assigning a variable name that combines two or more words.

--There is a way to include the value of the variable in the string. By using # {variable name} in the character string, the variable can be replaced with the assigned value and included in the character string. This is called "variable expansion".

--Variable expansion is only possible for strings that use double quotes. Note that in the case of single quotation, variable expansion is not performed and it is output as a character string as it is.

--Since the array is also one value, it can be assigned to a variable. By convention, variable names that assign arrays are often plural.

-Use the each statement for iterative processing. By using each statement, the elements of the array can be extracted in order and processed. Each statement is "array.each do |Variable name|, And write the process you want to execute before "end". Each statement iterates as many times as there are elements in the array. The elements of the array are entered into the variables enclosed in "|" one by one, and the processing in each statement is executed on that. The variable name (name) in each statement can be given any name, but it is customary to use the singular form of the variable name (names) of the array.

--The range in which each variable can be used is called the scope.

--As shown in the figure below, the hash can be written with a colon ":" at the beginning instead of a character string. This way of writing ": name" is called a symbol. A symbol is a way of writing a character with a ":" at the beginning instead of enclosing it in "" "or"'". Strings and symbols are strictly different, but they can basically be used in the same way.

--When using a symbol for the hash key, you can omit it. Specifically, ": key =>" can be omitted as "key:". Even if it is abbreviated, the key is a symbol, so when getting an element, it is necessary to use a symbol like puts user [: name].

--In an instance method, "self" refers to the instance itself.

--You need an explicit receiver to call the method. In the case of a class method, self is specified as the receiver.

--Unique value for each instance: Instance variable Common value for each instance: Class variable

Recommended Posts

Ruby learning points (basic)
Ruby learning 4
Ruby learning 5
Ruby learning 3
Ruby on Rails basic learning ①
Ruby learning 2
Ruby learning 6
Ruby learning 1
Ruby Learning # 25 Comments
Ruby basic terms
Ruby Learning # 13 Arrays
Ruby Learning # 34 Modules
Ruby Learning # 14 Hashes
Ruby Learning # 33 Inheritance
Ruby Learning # 15 Methods
Ruby Learning # 30 Initialize Method
Ruby Learning # 29 Classes & Objects
Ruby Learning # 20 Case Expressions
Ruby Learning # 24 Exponent Method
ruby basic syntax memo
Ruby Learning # 17 If Statements
Ruby Learning # 21 While Loops
Ruby Learning # 31 Object Methods
Ruby Learning # 27 Writing Files
Ruby Learning # 35 Interactive Ruby (irb)
Java learning memo (basic)
Ruby Learning # 9 Math & Numbers
Ruby Learning # 28 Handling Errors
Ruby Learning # 26 Reading Files
ruby memorandum (basic edition)
Ruby Learning # 23 For Loops
Ruby Learning # 16 Return Statement
Ruby Learning # 2 Drawing a Shape
Basic methods of Ruby hashes
Ruby on rails learning record -2020.10.03
Basic methods of Ruby arrays
Ruby on rails learning record -2020.10.04
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Java basic learning content 5 (modifier)
Ruby Learning # 18 If Statements (Con't)
Ruby Learning # 11 Building a Calculator
Ruby Learning # 99 Personal Programming Notebook
Ruby on rails learning record-2020.10.07 ②
Ruby Learning # 10 Getting User Input
Ruby Learning # 32 Building a Quiz
Ruby Learning # 8 Working With String
[Ruby] List of basic commands
Ruby on rails learning record-2020.10.07 ①
Ruby on rails learning record -2020.10.06
Ruby methods and classes (basic)
Java Basic Learning Content 8 (Java API)
Ruby on Rails Basic Memorandum
Java basic learning content 4 (repetition)
Review of Ruby basic grammar
Ruby Learning # 19 Building a Better Calculator
Completed Progate Ruby Learning Course III
Learning Ruby with AtCoder 6 [Contest 168 Therefore]
Basic knowledge of Ruby on Rails
Completed Progate Ruby Learning Course II
Java basic learning content 3 (operator / ternary operator)