Ruby and rails

Source: Internet
Author: User

1, string, which is similar to a character array

2. About [M. N] and [M... n]

ClassTestruby <test: Unit: testcase

Atog = ['A', 'B', 'C', 'D', 'E', 'F', 'G']

DefTest_sub_array

Assert atog [2,4]. Length =4

End

DefTest_sub_array_close

Assert atog [2..4]. Length =3

End

DefTest_sub_array_open

Assert atog [2...4]. Length =2

End

End

The ruby language also hinders productivity, although small;

1. Can you remember [M .. n] and [M .. n] which include N and which does not include n?

2. Are you sure you don't shake your hands when coding? Are you sure you have the wrong decimal point?

Of course, there are not many areas in the array range, or you have a unit test to escort, basically there is no impact

But I always think it can provide more obvious methods.

1. For example, the differences between [M.. N), [M. N], (M. N], and so on are not obvious.

2. Only one of them is supported. To express another meaning, you only need to add or subtract 1 when passing the parameter n.

 

Avoid it as much as possible in the future

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.