Private instance variables 
Author Message
 Private instance variables

In all the discussion about private instance variables, I don't think I've seen
the following method of differentiation:

  class X


  end

Is this possible or desirable?

--
Gavin Sinclair                                       Software Engineer
Sydney, Australia                            Soyabean Software Pty Ltd



Tue, 29 Mar 2005 10:02:04 GMT  
 Private instance variables


 It was proposed but you can't use it. For example

   class A
      def initialize

      end
   end

   class B < A; end

   b = B.new

   class B

   end

 When ruby execute attr_private, it has lost the information that the

 You must know at compile time, if an instance is class local.

Guy Decoux



Tue, 29 Mar 2005 13:36:49 GMT  
 Private instance variables
Hi,

I am sorry that I don't know much about the OO theory (haven't read that
Bertrand Meyer's book).  But the argument below made me think of two
questions:

1) From a general OO theory point of view, is it good if a subclass makes


2) If the answer to 1) is yes, or even just allowable, then probably is it
just a matter of implementation?  For example,

Suppose each class has two hashes: one for protected variables and one for

order of search is as follows:

    1) Search in the private hash.
    2) If not found, search in the protected hash.
    3) If not found, search in the parent protected hash, and repeat step
3) as necessary.



    1) Search in the private hash.
    2a) If found, do nothing.
    2b) If not found, search in the protected hash.
    3a) If found, move the symbol (key) and its value from the protected
hash to the private hash.

hash.

With this implementation, when "b = B.new" is executed, this is the state
of the class hashes:


    class B:    prot.keys = []        priv.keys = []


class hashes:






I know that Ruby internal implementation is currently not like this and
this new algorithm has some issue on efficiency.  But in this discussion,
the question that we want to answer is whether we *can* or *cannot* use

implementation, so to speak.)

Regards,

Bill
==========================================================================

Quote:



>  It was proposed but you can't use it. For example
>    class A
>       def initialize

>       end
>    end
>    class B < A; end
>    b = B.new
>    class B

>    end
>  When ruby execute attr_private, it has lost the information that the

>  You must know at compile time, if an instance is class local.
> Guy Decoux



Tue, 29 Mar 2005 22:31:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Instances incorrectly sharing instance variables?

2. Class sees privates of instances...

3. Private class and instance methods?

4. instances of classes and instances of instances

5. PRIVATE variables (was parameters)

6. Lots of Public and Private variables - no penalties on modern PC.

7. Public\private memory variables

8. Private variables can be changed outsid e?

9. Private variables can be changed outside?

10. Making Instace Variables Private/Local

11. private variables

12. private variables (again)

 

 
Powered by phpBB® Forum Software