it strikes me as curious....

i've spent quite a bit of time wrestling with some special attr_* module 
methods for use with CGI and i was quite concerned with honoring the full 
bredth of reader, writer, and accessor even though it meant more work; that 
is to say if i just used accessor it would be a lot easier. and that's when 
it hit me: if i don't want the external world reading and/or writing to my 
object's instance variables, why wouldn't i just set the access control to 
private (or protected)?

class AttrDemo
	attr_accessor :readme
	protected :readme=
end

granted this adds in a touch more code, but that's not the point i'm making. 
i'm only pointing out that in effect this serves the same purpose as:

class AttrDemo
	attr_reader :readme
end

the only differenece being that in the first example i have a setter method 
available to the class itself. fine with me.

except for the fact that instance variables can spring into existence 
dynamically, i wonder why they aren't simply attr_accessor by default and 
access control the sole means by which we make them visible or invisible to 
the outside.

so, in realizing this, i modified my attr_* methods to return their effected 
methods so that i could pass them on to an access control method. 
unfortuantely the access control methods will not take arrays. :-( it would 
be nice if they used #flatten so they could. i tried to rewrite them that 
way, but in doing so i lost the ability to have them affect the subsequent 
defs when given without arguments. so instead i had to create three new 
methods: #privatize, #protect and #publicize to do the job. additionally i 
added two new methods #writers and #readers which act as filters, such that 
one can do things like:

	privatize attr_writer :a  			# a=() is private
	protect writers attr_accessor :b  	# a() is public, a=() is protected

does this seem beneficial? is it over kill? is there a better way? what do you 
think of the original notion?

-- 
tom sawyer, aka transami
transami / transami.net


                                   .''.
       .''.      .        *''*    :_\/_:     .
      :_\/_:   _\(/_  .:.*_\/_*   : /\ :  .'.:.'.
  .''.: /\ :   ./)\   ':'* /\ * :  '..'.  -=:o:=-
 :_\/_:'.:::.  | ' *''*    * '.\'/.' _\(/_'.':'.'
 : /\ : :::::  =  *_\/_*     -= o =-  /)\    '  *
  '..'  ':::' === * /\ *     .'/.\'.   '._____
      *        |   *..*         :       |.   |' .---"|
        *      |     _           .--'|  ||   | _|    |
        *      |  .-'|       __  |   |  |    ||      |
     .-----.   |  |' |  ||  |  | |   |  |    ||      |
 ___'       ' /"\ |  '-."".    '-'   '-.'    '`      |_.
------------------------------------------------------------