Ruby method name

Source: Internet
Author: User

The following pattern is commonly used to define method names in ruby.

Def method_name (arg1, arg2) # Some codeend

However, it is often seen in the code of books or other authors that=? !These three special weird symbols serve as the suffix of the method name.

 "? "It is used to indicate the predicates, that is, the method to return the Boolean value, such as array. Empty? (Determines whether the element in the array is null ).

 

 "!"The exclamation point at the end of the method name indicates that you need to be careful when using this method. Many Ruby core Classes define paired methods. They have the same name, but the end difference is a "!", In general, the method is returned without an exclamation mark.

Call a copy of this method. The method with Two exclamation points is a mutable method that modifies the original object, such as sort and sort in the array class!

 

"="When you want to set the value of an attribute, directly copying these variables conforms to everyone's general understanding. In Ruby, you can create a method ending with an equal sign to achieve this goal.

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.