Ruby Learning Notes

Source: Internet
Author: User

Some difficulties in learning ruby language learning comprehension
    • The Ruby language is a relatively simple language because all of its design principles are object-oriented, so it's especially handy to use. Of course, the main reason is that it has the same grammatical features as Python, swift and so on, which makes him very convenient to use.
The following summarizes several of my daily problems encountered. 1. The variable is readable and writable.
Attr_reader:name indicates that name is read-only
Attr_write:name Indicates that name only writes
Attr_accessor:name Represents a readable and writable
2. About module.
    • The module is similar to class, where you can define methods and then use them in other classes. For example, there can be references in the following ways.
module M    def mm        puts "helloworld!"    endendclass A include M def initalize puts "aa" endenda = A.newa.mm
3. About the Public keyword and the keyword private
    • Public represents a common excuse, and you can use this class's excuse function in other classes. Private means that the other classes cannot be used unless they are available in their own classes.
class Application    attr_accessor :status    def initialize    end public def print_status puts "all system go!" end private def password @password = 123456 endend

 

Ruby Learning Notes

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.