Ruby Study Notes (1)

Source: Internet
Author: User

Ruby Study Notes

Reference Book -- Why's (Poignant) Guide to Ruby: Data Types and other basic operation information in csdn resources Ruby Variables

Any plain, lowercase word is a variable in ruby
For example, X, Y, banana2, phone_a_quail

Numbers

A series of digits which can start with a plus or minus sign
For example, 10000 ,-

Strings

Any sort of character surrounded by quotes
For example, "sealab", '123'

Symbols

Words that look just like variables, start with a colon
Example: A,: B: ponce_de_leon

Constants

Words like variables, but they are capitalized
For example, time, array, bunny_lake_is_missing

Methods

Attached to the end OD variables and Constants by a dot
For example, front_door.open
Front_door.is_open? Used to test the use of door_test_to_see_if_its_open

Method arguments

Attached to the end of a method, usually surrounded by parenthese and separated by commas
For example, front_door.paint (3,: Red)
The front_door.paint (3,: Red). Dry (30). Close () function can be chained for execution.

Class Methods

Usually attached after variables and constants, used a double colon
For example, door: New (: oak)

Global Variables

Variables which begin with a dollar sign
For example, $ X, $1, $ chunky

Instance variables

Variables which begin with an AT symbol
For example, @ X, @ Y, @ only_the_chunk

Class variables

Variables which begin with double at symbols
For example, @ X, @ Y, @ I _will
Class variables give an attribute to initialize related objects in ruby

Blocks

Any code surrounded by curly braces
For example, 2. Times {print "Yes. I am a student, but never agian "}
Loop do
Print "much better"
Print "I am better"
End

Block arguments

A set of variables surrounded by pipe characters and separated by commas
For example, | x |, | Y |, | up, down |
Use at the beginning of a block such as {| X, Y | x + y}

Ranges

Two values surrounded by parentheses and separated by an ellipsis
For example, (1 .. 3) indicates the number from 1 to 3, ('A' .. 'Z') indicates lowercase letters
If a third dot is used, the last value in the range is exclueded
For example, (0... 5) indicates from 0 to 4

Arrays

A list surrounded by square brackets and separated by commas
For example, {1, 2, 3}, {'coat', 'mittens', 'snowboard '}

Hashes

A dictionary surrounded by curly braces, use an arrow like an equals sign
For example, {'A' => 'invalid dvarx', 'B' => 'badgar '}

Regular Expressions

A set of characters surrounded by slashes
For example,/Ruby/,/[0-9] +/,/^ \ D {3}-\ D {3}-\ D {4 }/

Operators

Only unfamiliar ones are listed here.

** = ~ !~ === .....
<=>

See figure

Keywords

Only unfamiliar ones are listed here.

Alias begin (different from begin) elsif end (different from end) Ensure module nil (should be similar to null) rescue retry self yield

See figure

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.