Open source, cross-platform (Windows, Linux, UNIX, etc.)
scripting language (less efficient), no need to compile, run directly
Grammar Nature, Introduction
Everything is an object.
Flexible language design (feel free to change the original design)
Powerful nlocks and Cloures.
Inheritance and Mixin
Ruby Gems (plugins, libraries, etc.)
Ruby Interpreter (interpreter): Mri,jruby,rubinius
Installation under CentOS
Yum Install-y Ruby
Version Ruby-v
. RB End
Variable type:
Local variables
Instance variable
Global variables
Constant
String variable name = "It"
Number variable num = 100
Array variable score = {.
Boolean Variable Is_pass = True
Hash variable user = {: name = "Zhang",: Age = 29}
Symbolic variables: Name to save unchanged data
View variable Object type: variable name. class
Method of calling object: Variable name. Method Name
Name.sort the name and does not modify the name content
name.sort! Sort name and modify the name content
Puts "Hello #{name}! "Referencing variable contents by #{}
The double quotes here are quoted as single quotes and are printed directly
= assigned value
= = Comparison is the same, the return value is TRUE or False
>,< is greater than or less than, the return value is TRUE or False
<=,>= is equal to or greater than or equal, the return value is TRUE or False
<=> Ship-type operator, return value -1,0,1
&& can be written as and logic with
|| can be written as or logical OR
! Can be written as not logical non-take reverse
If Judgment statement
...... Executed for true, not executed for false
End
If Judgment statement
......
Else
.......
End
If Judgment statement
......
elsif Judgment Statement
......
Else
.......
End
All other return values are true except for false and nil in Ruby
Unless conditional judgment statement #为假
......
End
Unless conditional judgment statement #为假
.......
Else
......
End
Case variable
When value
Puts ""
When value
Puts ""
End
1..59 is a range, from 1-59
Infinite loops
Loop do
Puts ""
End
Count = 0
Loop do
Puts ""
Count + = 1
If Count > 10
Break
End
End
Conditional loop:
Count = 0
While Count < 10 is true when executed
Puts ""
Count + = 1
End
Count = 10
Until count < 1 for false execution
Puts ""
Count-= 1
End
Iterators
10.times do
Puts ""
End
1.upto (10) from 1 to 10
10.downto (1)
1.step (10.2) from 1-10, but every +2
method, which can be repeatedly called multiple times by definition
def method Name
.....
End
The method name must be lowercase, and you can use _ to use the parameter
def method name (parameter)
.... #{parameter}
End
(* parameter) variable length parameter, automatic conversion of multiple parameters to an array
(parameter =1) parameter default value
return value
This article is from the "Heavenly Soul Eternal" blog, please be sure to keep this source http://tianhunyongheng.blog.51cto.com/1446947/1693170
Ruby Learning Notes (incomplete version)