[Ruby on Rails] Deep (2) Ruby Basic syntax

Source: Internet
Author: User
Tags ruby on rails

1. Debug & comment & Print output debug

Ruby is an interpreted language, a script, and on Linux, scripts cannot be executed in three ways:

1. Run the script with the interpreter

Interpreter  script File

That is:Ruby script File

2. Run the script directly

In the script file, use the

#! Script Interpreter

Define the script interpreter path, then grant the script execute permission, then run directly

./script File

Can.

3. Run the script inside the interpreter

[Email protected]:/home/ywt/ror_tests/ruby_tests# irb2.1.5:001 > str = "SDFSDF" = "SDFSDF" 2.1.5:002 > puts str SDFSDF = nil2.1.5:003 > Print strsdfsdf = nil2.1.5:004 >

PS: Suggested directly with the first, the second is more troublesome, the third is more ugly (of course try syntax can use this)

Comments

Coment.rb

#single line commentstr = ' Hello World ' =beginthis are a test ofmutiple line comments=endputs str

The test output is as follows:

[Email protected]:/home/ywt/ror_tests/ruby_tests# Ruby Comment.rbhello World

That

#单行注释
=begin Multi-line Comment =end

Print output

Print_test.rb

str = ' Hello World ' puts Strprint strputs ' ========= '

Test output

[Email protected]:/home/ywt/ror_tests/ruby_tests# Ruby Print_test.rbhello Worldhello World =========

That

Puts  str  =  print str  + print New_line  

(New_line under Windows is ' \ r \ n ', Linux above is ' \ n ')

Class General definition
Class Aclassend

Note: The first letter of a class name must be capitalized! (Python does not require this)

General definition of inheritance
Class Child<fatherend

That is, the inheritance character is ' < ';

Question: Do you support multiple inheritance?

Member member variable member function

[Ruby on Rails] Deep (2) Ruby Basic syntax

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.