Robert Dober
3/2/2009 12:01:00 PM
On Mon, Mar 2, 2009 at 12:05 PM, abc <arcadiorubiogarcia@gmail.com> wrote:
> I'm the OP. Thank you all for your replies.
>
> Sorry if the question wasn't clear enough. I wanted to register all
> the instances of a class, so the original idea was to use a hash class
> variable to do that.
>
> Of course there are a number of gotchas if you want to make the code
> concise using this approach, so an alternative solution is to declare
> another class, make it a Singleton and use it for that purpose.
>
> I'm not a seasoned Ruby programmer, but I think I was totally right in
> the idea of using class variables (@@hash). I cannot see why some
> people are surprised. I'd be very happy if somebody could shed some
> light on the issue, because maybe I'm missing something...
>
oops sorry, you made your point already.
Well if you use class variables they will be shared by all your
subclasses, if that is what you want, perfect.
Often one does not want that behavior, hence the surprise ;), because
a superclass generally shall not know about its subclasses.
Implications on maintenance and reuse are heavy! But there are cases
where it is fine, just ponder the question carefully :)
Cheers
Robert
>
--
There are some people who begin the Zoo at the beginning, called
WAYIN, and walk as quickly as they can past every cage until they get
to the one called WAYOUT, but the nicest people go straight to the
animal they love the most, and stay there. ~ A.A. Milne (from
Winnie-the-Pooh)