From: Dan Zwell Date: 2007-05-26T12:32:37+09:00 Subject: Re: Global Array? Sy Ys wrote: > I've got a class which calls itself several times (recursive). While > this class is calling itself, I want it to be appending a global array ( > << ). I can't figure out how to make the array itself global, so for now > each time the class calls itself, it creates the array anew again. Help? > class Klass def recurse $klasses = Array.new unless \ global_variables.include?("$klasses") and $klasses.is_a?(Array) unless $klasses.size > 40 k = Klass.new $klasses << k k.recurse end end end Note that I found the "and $klasses.is_a?(Array)" bit necessary because the parser seems to initialize the global array $klasses when it first comes across the word. Might I suggest using a class level variable instead (@@klasses)? It seems appropriate. They are "almost global." Dan