dblack wrote:
> Anyway -- I'm trying to follow along but not sure what you mean by
> classes that have nothing but class methods and class data.  Can you
> give a code example of such a class?
>

Here's a very simple example (a global counter):

<code>

class SingletonCounter
  private_class_method :new
  attr_accessor :count
  @@counter = nil  # class var which pts to instance
  def initialize( count )
    @count = count
  end
  def SingletonCounter.create
    @@counter = new( 0 ) unless @@counter
    @@counter
  end
  def increment( inc_amt )
    @count += inc_amt
    return @count
  end
end

class Counter
  @@count = 0                      # class variable
  def Counter.increment( inc_amt ) # class method
    @@count = @@count + inc_amt
    return @@count
  end
end

sc = SingletonCounter.create
print sc.increment( 9 )
print sc.increment( 4 )

sc2 = SingletonCounter.create
print sc2.increment( 3 ) # points to same underlying obj as sc

c = Counter.new
print Counter.increment( 9 )  # in C#, you could do c.increment( 9 ) 
here
print Counter.increment( 4 )

c2 = Counter.new
print Counter.increment( 3 )

</code>

The first class is a true singleton and the second class is what is *in 
essence* a singleton, but known as a static class in C#.  One thing that 
C# will let you do that makes this more transparent is 
instancevar.staticmethod().  That apparently isn't the case in Ruby, so 
that makes them less equivalent.  (I suspected there would end up being 
some syntax difference between the two, but the point I was making was 
that they were the same in concept).

I don't know if any of this is really relevant, but hopefully you 
understand statics, singletons, and C# a little better now. :)  BTW, 
this discussion is continued in another thread called 'About class 
methods'.

--J

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