Ruby: Adds attr_accessor, attr_reader, and attr_writer to class docs

This commit is contained in:
David Underwood 2013-12-01 21:42:51 -05:00
parent a36cee194b
commit 02044c1eab

View File

@ -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)