It will be an article to review the basic notation of ruby again.
#Character string → character string
'1'.to_s # => "1"
#Numerical value → character string
1.to_s # => "1"
#nil → blank string
nil.to_s # => ""
#Boolean value true → of character string"true"
true.to_s # => "true"
#Boolean false → string"false"
false.to_s # => "false"
#Normal writing
object.Method(Argument 1,Argument 2,Argument 3)
#You may omit the parentheses
object.Method argument 1,Argument 2,Argument 3
#With no arguments
object.Method
#Variable name should be snake case
first_name = user.first_name
#Camel case is not customarily used
firsfName = user.first_name
#Variables starting with a number will result in an error and cannot be used
2_discount_price = 200
A string can be represented using either single quotes ('') or double quotes (""). Basically, use single quotes, and use double quotes when expanding expressions.
#String
'This is a string'
"This is a string"
#When expanding an expression
i = 'String'
"this is#{i}" # => this is文字列
# &&Is an AND logical operation
#True if both condition 1 and condition 2 are true, false otherwise
Condition 1&&Condition 2
t1 = true
t2 = true
f1 = false
t1 && t2 # => true
t1 && f1 # => false
##Condition 1 is true if either condition 2 is true, and false if both are false.
Condition 1||Condition 2
t1 = true
t2 = true
f1 = false
f2 = false
t1 || t2 # => true
t1 || f1 # => true
f1 || f2 # => false
Methods ending in? Are customarily methods that return boolean values.
#Returns true if it is an empty string, false if it contains characters empty?Method
''.empty? # => true
'AIUEO'.empty? # => false
Recommended Posts