mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 10:25:23 +00:00
Merge pull request #428 from davefp/ruby_attr_accessor
[ruby/en] Adds attr_accessor, attr_reader, and attr_writer to class docs
This commit is contained in:
commit
53272e5f11
@ -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