Getting Started with Ruby (scripting language for object-oriented programming)

Source: Internet
Author: User
Tags uppercase letter



Ruby is a scripting language for simple and fast object -Oriented programming (object-oriented programming).



Brief introduction


Ruby is open source and is available on the web for free, but requires a license .
Ruby is a universal, interpreted programming language .
Ruby is a true object-oriented programming language.
Ruby is a server-side scripting language similar to Python and Perl.
Ruby can be used to write generic Gateway Interface (CGI) scripts.
Ruby can be embedded in Hypertext Markup Language (HTML).
Ruby syntax is simple, which makes it quick and easy for new developers to learn Ruby.
Ruby has a similar syntax to many programming languages such as C + + and Perl.
Ruby is extensible, and large programs written in Ruby are easy to maintain.
Ruby can be used to develop Internet and Intranet applications.
Ruby can be installed in Windows and POSIX environments.
Ruby supports many GUI tools, such as TCL/TK, GTK, and OpenGL.
Ruby makes it easy to connect to DB2, MySQL, Oracle, and Sybase.
Ruby has a rich built-in function that you can use directly in your Ruby script.

features







Fully object-oriented, in the Ruby language, anything is an object, including basic data types in other languages, such as integer variables without types, and ruby variables can hold any type of data.    Everything has a value, whether it's a number or a logical expression or a statement. The Ruby language is elegant and can be read without the need for annotations.







Ruby's variables have certain rules, starting with $ must be global variables, starting with @ is an instance variable, and @@ 开头 with a class variable.    The constant begins with a capital letter, which is useful for command completion of a text editor, such as typing $ and the first letter under Vim, and then tapping Ctrl+p, which complements the global variables in the file as well as the associated file. Ruby is a dynamic language, and you can modify previously defined classes in your program, and classes that have already been defined can be modified at run time. You can also define a method specific to that instance in an instance of a class, which is called a singleton method. Grammar





The keywords in Ruby are as follows:



Modules Definition: module



Class definition: Class



Method definition: Def,undef



Check type: Defined?



Conditional statement: if,then,else,elsif,case,when,unless



Looping statements: For,in,while,until,next,break,do,redo,retry,yield



Logical judgment: Not,and,or



Logical value: True,false



Null value: Nil



Exception handling: Rescue,ensure



Object reference: Super,self



Start of block: Begin/end



Embedded module: Begin,end



File Related: __file__,__line__



method returns: Return



Aliases: Alias






Note: The Begin module is equivalent to a macro in the C language, and the end module is used for some finishing work. With require,include, the syntax definition for begin and end should be canceled.






The operators in Ruby are as follows: priority (from high to low)



can override



Operator



Describe



Y



[], []=



Array subscript, array element assignment






Y



* * Ride the Underworld



Y



! , ~, +,-



Non, bit non, unary plus (positive), minus






Y



*、/、%



Multiply, divide, mold






Y



+,-



Add, Subtract






Y



>>, <<



Move right, move left






Y



&



Bit and






Y



^, |



Bit XOR, bit, or






Y



<=, <, >, >=



Less than or equal to, less than, greater than, greater than or equal






Y



<=>, = =, = =, =~,! =,!~



Various equality judgments (cannot rewrite =~,! =,!~)






N



&&



Short Circuit and






N



||



Short Circuit or






N



..、...



Start point of interval to end point






N



? :



Ternary conditional operators






N



=,%=, ~=,/=,-=, + =, |=, &=, >>=, <<=, *=, &&=, | | =, **=



Various assignment values






N



Defined?



Check type






N



Not



Logical Non-






N



Or, and



Logical OR, logical, and






N



If, unless, while, until



Judgment and circulation






N



Begin, End



Define the scope of methods, classes, modules




Attention:

It is important to note that Ruby does not have "+ +", "--" operators, but can be implemented by "+=1", "-=1".

Some conventions for Ruby identifiers:

Local variables start with lowercase letters or underscores

Global variables begin with a dollar sign.

Instance variable starts with @

Class variables start with @@

A constant or class name begins with an uppercase letter.

The NIL keyword in Ruby is very special. Nil represents a concept of an empty set that is similar to null in other languages. As with other languages, Ruby has only nul and false for false in logical judgment, and all other expressions are true.






Getting Started with Ruby (scripting language for object-oriented programming)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.