> How would you do that?

This is pretty awkward within Ruby.  The first parts describes a (semi)
solution for an individual class  -  the parsing rules of Ruby seem to
imply that a plain "sym=  l"  is  never interpreted as "self.sym=(l)" .
Maybe
it is possible to change the parsing rules a bit so that  sym= x is
interpreted as "self.sym=  l"  and/or make the __this__ pointer
superfluous all together?  The second part is the automated version ..

class A
     def  __set_this__ __this__
          @__this__= __this__
     end
     def initialize (a,b) # we could initialize  @__this__ here
     end                         # but this cannot be automated
     def A.new ( *r, &p)
         tmp= super(*r,&p)
          tmp.__set_this__  tmp
     end
     attr_accessor  :sym
     def set_sym x
          @__this__.sym  = x
     end
     def  set_sym_fail x
          sym=  x  # this does not work
     end
     def  try
          set_sym        "only set_sym works"
          set_sym_fail "both work"
     end
     # other stuff
end

y=  A.new(3,4)
y.try
p y.sym   # "only set_sym works"

 ##########################

class  Class
module ThisPointerModule
    def  __set_this__ __this__
        @__this__= __this__
     end
     def  __this__
          @__this__
     end
     def new ( *r, &p)
          tmp= super (*r,&p)
          tmp.__set_this__  tmp
     end
end
    def attr_inner_accessor  sym
          attr_accessor sym
          include ThisPointerModule
          extend ThisPointerModule
          module_eval   "def set_#{sym.to_s} (x) \
                       @__this__.#{sym.to_s} =  x end"
     end
end

# test
class B
    attr_inner_accessor  :sym
    def  try
          set_sym        "set_sym works"
    end
end

y = B.new
y.try
p y.sym  # "set_sym works"


Christoph

"Dave Thomas" <Dave / PragmaticProgrammer.com> wrote in message
news:m2bsu4oxgs.fsf / zip.local.thomases.com...
> "Christoph Rippel" <crippel / primenet.com> writes:
>