Being only a few hours into learning Ruby I've read very little about
class variables yet but decided to experiment with them anyway as an
alternative to using a global variable. I typed in the code below and
having created a few 'Cheese' objects was (un)surprised to find that it
just worked. Each cheese is assigned it's own idnumber.

I'd just like to know if using class variables in this way is likely to
cause any problems?

Secondly, from the little I've discovered so far, is it correct that
there is no way to delete an object when it is no longer required? How
would I handle millions of transient objects, for example particles that
live and die. Over the life of the program millions of such objects
might be created but only thousands may be 'alive' at any one time.


class Cheese
  @@idcounter=0
  attr_accessor :name, :flavour
  @idnumber
  def initialize
    @idnumber = @@idcounter
    @@idcounter += 1
  end
end

TIA

Paul

-- 
Posted via http://www.ruby-forum.com/.