Sorry for the "nitpicky question" but I'm new to Ruby and was wondering why attr_accessor was used to implicitly define accessor AND a mutator when the name attr_accessor itself has nothing alluding to mutation (i.e. attr_accessor_mutator).
It's just a shorthand for attr_reader and attr_writer. Yes it could use a
better name I suppose, I guess brevity won out. If you only want a strict
accessor, use attr_reader.
···
2009/6/17 bjorn borg <borgagassi@yahoo.com>
Sorry for the "nitpicky question" but I'm new to Ruby and was wondering why
attr_accessor was used to implicitly define accessor AND a mutator when the
name attr_accessor itself has nothing alluding to mutation (i.e.
attr_accessor_mutator).
--
James Coglan
http://jcoglan.com
bjorn borg <borgagassi@yahoo.com> writes:
Sorry for the "nitpicky question" but I'm new to Ruby and was
wondering why attr_accessor was used to implicitly define accessor
AND a mutator when the name attr_accessor itself has nothing
alluding to mutation (i.e. attr_accessor_mutator).
Accessors = Readers ∪ Writers
···
--
__Pascal Bourguignon__
Hi --
···
On Wed, 17 Jun 2009, bjorn borg wrote:
Sorry for the "nitpicky question" but I'm new to Ruby and was
wondering why attr_accessor was used to implicitly define accessor
AND a mutator when the name attr_accessor itself has nothing
alluding to mutation (i.e. attr_accessor_mutator).
You can think of it as "access" in the sense of "read/write access",
as opposed to just one or the other (attr_reader/writer).
David
--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2\)
"Ruby 1.9: What You Need To Know" Envycasts with David A. Black
http://www.envycasts.com