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