Why is attr_accessor also mutator?

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

2009/6/17 bjorn borg [email protected]

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.

bjorn borg [email protected] 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

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