Hi --

On Thu, 10 Jun 2004, Paul Brannan wrote:

> On Wed, Jun 09, 2004 at 04:08:38PM +0900, wang wrote:
> > class Test
> >   def func
> >     self.test   #use self
> >   end
> >   
> >   private
> >   def test
> >     p "test"
> >   end
> > end
> 
> If you want to do this, use protected instead of private.
> 
> I guess this means you can't have private accessors:
> 
>   class Foo
>     def initialize
>       self.foo = 1
>     end
> 
>     private
>     attr_accessor :foo
>   end
> 
> but I've never seen a case where I wanted to do that.

For some reason it does seem to allow this though:

  class Foo
    private
    def x; end
    attr_accessor :foo

    public

    def initialize
      self.x rescue puts "x didn't work"  # just for benchmark
      self.foo = 1
      p foo
    end
  end

  Foo.new   # x didn't work
	    # 1


(ruby 1.8.1 (2003-12-25) [i686-linux])

Maybe the self in self.foo= serves as a "this isn't a variable"
marker, but then is somehow discarded, so that it doesn't serve as a
"this method call has an explicit receiver" marker?


David

-- 
David A. Black
dblack / wobblini.net