mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 02:15:57 +00:00
Ruby: Adds attr_accessor, attr_reader, and attr_writer to class docs
This commit is contained in:
parent
a36cee194b
commit
02044c1eab
@ -323,6 +323,13 @@ class Human
|
|||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The above functionality can be encapsulated using the attr_accessor method as follows
|
||||||
|
attr_accessor :name
|
||||||
|
|
||||||
|
# Getter/setter methods can also be created individually like this
|
||||||
|
attr_reader :name
|
||||||
|
attr_writer :name
|
||||||
|
|
||||||
# A class method uses self to distinguish from instance methods.
|
# A class method uses self to distinguish from instance methods.
|
||||||
# It can only be called on the class, not an instance.
|
# It can only be called on the class, not an instance.
|
||||||
def self.say(msg)
|
def self.say(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user