From: Paul Brannan Date: 2002-09-06T22:39:37+09:00 Subject: Re: Ruby aesthetics On Fri, Sep 06, 2002 at 09:45:32AM +0900, Yukihiro Matsumoto wrote: > It's in the ToDo list. Private instance variables will be something > like @_foo. But it's pretty hard to implement. If someone come up > with a good idea, I'm glad to hear. The way I implemented it in Ruby was: 1) Each class has a Hash which maps object id to a table of private instance variables. 2) When I access a private instance variable, I use a function get_piv, which uses some set_trace_func magic to know the class from which it was called. It then looks up the variable in the above Hash. 3) I also hook the initialize method of every class that has private instance variables to define a finalizer that removes the entry in the Hash for the given object when it is destroyed. Problems: 1) Since the private instance variable is not part of the object itself, it will not get marshalled/demarshalled. 2) Determining which class the variable belongs to can be tricky in Ruby. I would imagine that this would be much easier in C. 3) set_trace_func is slow. 4) I'm not sure how well this maps to C. It should work, but it may not be the best solution. BTW, when you say that private instance variables are "hard to implement," what exactly do you mean? What barriers have you run into while trying to implement them? Paul