Private Writer

From: Matthew, Graeme [mailto:Graeme.Matthew@mercer.com]
If I create reader and writer attributes

eg
attr_reader :code, :name, :telephone
attr_writer :name, :telephone

On accessors:
if you define, for example,
class Obj
attr_accessor :foo
end
and the object client use obj.foo and obj.foo= extensively, and you later
want to add side effects to changing/looking at @foo, you can just get rid
of the accessor and go for functions:
class Obj
#attr_accessor :foo (not needed anymore)
def foo
call_side_effect(:foo_looked_at)
return @foo
end
def foo=(newFoo)
call_side_effect(:foo_changed)
@foo = newFoo
end
end

Happily, no client code needs to change. You’ve transparently changed
behaviour, preserving contracts. You are a happy little vegemite.

Similarly, for private, just throw private in above the two functions in the
last example. You break the client code, but thats the nature of privacy.

David, the Other.