Rules found in ruby

Source: Internet
Author: User

1. Constants

Although Ruby only requires uppercase letters of a constant, we recommend that you use uppercase letters of a constant name for better readability.

Class persons
Finger = 10; # define Constants
Puts "Everyone has" + finger. to_s + "root finger" # output
Finger = 11; # assign a value to a constant again
Puts "some people can also have" + finger. to_s + "root finger" # re-Output
End

Class Test
Const = "Hello world! "; # Define Constants
Puts const + "access in parent class" # internal class access constant
Def info # Creation Method
Puts const + "access in method" # access constants in class methods
End
Class testchild # create an internal class
Puts const + "access in internal classes" # access constants in internal classes
End
End
Class sub <test # create a subclass
Puts const + "access in subclass" # access to the parent class constant in subclass
End
Puts test: const + "Usage: Access to constants out of the range" # usage: To access constants in the test class
T = test. New # create a test object t
T.info # access the info method in test through T

Class first
Info = "Ruby"; # define Constants
End
Class second
Info = "hello" # define Constants
Class firstchild <first
Puts info # constant used to access external classes
Puts first: info # accessing constants in the parent class
End
End

2. Variables

In Ruby, local variables must be lowercase letters (~ Z) or begin with an underscore

The global variable starts with "$.

3. P and puts and print

P "\ ta"

Puts "\ ta"

Output:

"\ Ta"
A

In common: it is used for screen output.

Differences:
After puts outputs the content, it will automatically wrap the text (if the content parameter is blank, only one line feed is output). If the content parameter contains an escape character, the output will first process the escape and then output
P is basically the same as puts, but does not process escape characters in parameters.
Print is basically the same as puts, but the line break is not automatically added to the end after the output content

 

4. Ajax needs to be imported in the head.

<% = Javascript_include_tag "prototype" %>

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.