Why is attr_accessor also mutator?

B

bjorn borg

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).
 
J

James Coglan

[Note: parts of this message were removed to make it a legal post.]

2009/6/17 bjorn borg said:
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.
 
P

Pascal J. Bourguignon

bjorn borg said:
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
 
D

David A. Black

Hi --

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top