-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
attr_reader :number # Let outside world read this value
attr_writer :number # " " " set it
attr_accessor :number # " " " read or set it
In practice, I've never used attr_writer. It's hard to imagine
something useful being write-only and not readable. (Insert
Perl wisecrack here.)
Hehe...I'll avoid the Perl wisecrack, but I can think of a couple scenarios
where attr_writer might be useful:
1) True write-only data, such as a password. For example, you might have
password=(pwd) to set the password, and verify_password(pwd) to compare the
password to a given string, but no password reader method. This is
especially useful if you store passwords in hashed form so that they cannot
be retrieved once hashed.
2) You might want to use a standard attr_writer generated writer method, but
provide a custom reader method. I do this all of the time with boolean
attributes, so I can add the '?' to the end of the reader method.
- --
Jason Voegele
Sodd's Second Law:
Sooner or later, the worst possible set of circumstances is
bound to occur.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAcp/1rFeZdK3QLzERAhgNAJ0ZZpDvz5OnItwHVSaA0z7MuKAnTwCfe7qX
xVw5mhB/UXbzZsVmrbLeTmg=
=xxYw
-----END PGP SIGNATURE-----