You should know the Ruby Code style _ruby topic

Source: Internet
Author: User

One, Space and tab
Indent with spaces (95.364%)
Use tab indent (4.636%)
Based on 1,001,987 submissions
Second, maximum line width
80 characters (92.618%)
120 characters (5.893%)
150 characters (1.489%)
Based on 1,057,374 submissions
Three, operator, colon, curly braces around, comma, semicolon after the use of space
Do not use spaces (73.366%)

Copy Code code as follows:

sum = 1 +2
A,b = 1, 2
1>2? True:false;puts ' Hi '
[1, 2, 3].each {|e| puts E}

Use spaces (26.634%)
Copy Code code as follows:

sum = 1 + 2
A, B = 1, 2
1 > 2? True:false; Puts ' Hi '
[1, 2, 3].each {|e| puts E}

Based on 911,301 submissions
Four, default parameters
Front and back spaces (59.151%)
Copy Code code as follows:

def some_method (arg1 =:d efault, arg2 = nil, arg3 = [])
# do something ...
End

No spaces or only one space (40.849%)
Copy Code code as follows:

def some_method (arg1=:d efault, Arg2=nil, arg3=[])
# do something ...
End

Based on 19,213 submissions
Five, long numbers
Do not use underline (97.984%)
Copy Code code as follows:
num = 1000000

Use underline (2.016%)
Copy Code code as follows:
num = 1_000_000

Based on 133,530 submissions
whether to omit parentheses when there is no argument
Ellipsis brackets (98.556%)
Copy Code code as follows:

def Some_method
# do something ...
End

Do not omit parentheses (1.444%)
Copy Code code as follows:

def Some_method ()
# do something ...
End

Based on 267,404 submissions
Whether to use parentheses around parameters when defining functions
Omitted (62.867%)
Copy Code code as follows:

def Some_method Arg1, arg2
# do something ...
End

Not omitted (37.133%)
Copy Code code as follows:

def some_method (Arg1, arg2)
# do something ...
End

Based on 365,121 submissions

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.