From: "David A. Black" Date: 2005-03-16T20:34:00+09:00 Subject: Re: [ruby2] will '@@' disapear in ruby2? Hi -- On Wed, 16 Mar 2005, Csaba Henk wrote: > On 2005-03-15, Lionel Thiry wrote: >>> Anyway, the short answer as far as I know is "no" :-) >> Too bad! :) > > I do like having them. In fact, they are globals, wrapped in the > namespace of a class/module. There are situations when you need such a > beast, and it's better than an explicit global... and better than using a > container as a constant (just because constans don't like being > reassigned), that's really ugly. > > My problem is that you can't really access them from the outside, unless > accessor method are set up. By "from the outside" I mean that from code > which is not in the scope of a "class/module Foo ... end" thingy. You can always use class_eval or instance_eval. I think part of the point is that they're specific to that scope. > Does anyone know, eg, how to define a class variable in a nameless > class? Do you mean like: def class_factory return Class.new { @@x = 1 } end class_factory.class_eval { puts @@x } # 1 David -- David A. Black dblack@wobblini.net