Seven weeks and seven languages-ruby-Day 1: Find a nanny

Source: Internet
Author: User

I feel that I will soon forget what I learned and will not leave anything. I read "seven weeks and seven languages" this time and record what I think is useful for future reference, this should be the beginning of the record.

Ruby is an object-oriented, interpreted, and dynamic scripting language.Object-orientedIt indicates that the language has the characteristics of encapsulation, inheritance, and polymorphism;Interpreted typeIt means that it is executed by the interpreter rather than the compiler;Dynamic typeThat is, the type is bound at runtime rather than during compilation;Script Language, It indicates that it is very short! Easy to use! It is interpreted and executed only during the call.

Programming Model: All objects, from a number to a bool value, are defined as objects and have their own methods.

JudgmentStructure: Both block and row formats are supported.

LogicJudgment: Logical judgment is only performed to the position where the value can be obtained. & and are both logical and. | and or are both logical or

RUby API documentation: Http://www.ruby-doc.org/core-2.0/

Programming Ruby: Http://www.ruby-doc.org/docs/ProgrammingRuby/

Method for replacing a part of a character: String # sub, string # gsub, string # Tr and string # []

Ruby regular expression:

Here are some common examples.

Matching character:

# \ D Number

# \ W letters and numbers

# \ S empty characters

Matching Method:

# = ~ The result is the matching position.

1 "aaaa1" = ~ /\ D/

# Match indicates the matched characters.

1/\ D/. Match ("aaaa1 ")

RUby region (range):

Generally, "..." or "..." is added between characters or numbers to indicate a range. This range is also an object !!

Include? Method: used to determine whether a value is in this region or not.

1 (1 .. 100). Include? (50)

Self-study:

1. Print the string "Hello, world"

1 p "Hello, world ."

2. Find the subscript "Ruby." in "Hello, Ruby .".

1 "Hello, Ruby." = ~ /Ruby ./

3. print your name ten times

1 10. Times {P "wyp "}

4. Print "This is 1" and 1 will change from 1 to 10.

X = 1

While x <= 10

P "this is # {x }"

X = x + 1

End

5. Run the ruby program from a file

Use RB as the file suffix, and then run it directly using the ruby command.

~ $ Ruby filename. Rb

Finally, I found a good online Ruby reference manual when I checked the information, recording it to prevent myself from forgetting: http://www.kuqin.com/rubycndocument/man/index.html

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.