From: "David A. Black" Date: 2008-06-09T15:05:15+09:00 Subject: Re: Singleton object vs. enhancing singleton class Hi -- On Mon, 9 Jun 2008, Paul McMahon wrote: > In ruby, as class are singleton objects, does anyone have any ideas when I'd just say: classes are objects. Like other objects, they can have methods added to them on a per-object basis (give or take the fact that "per-object" in the case of a class actually includes subclasses). > a a singleton object should be used vs. simply adding methods to the > class? For example, > > class Foo > include Singleton > def bar > end > end > > vs. > > class Foo > def self.bar > end > end I don't see these techniques as addressing the same problem or being likely candidates to replace each other. I'd go by what you need. If you need a class that has only one instance, then use Singleton. If you've got a situation where there's class-level (as opposed to instance-level) knowledge involved, then use a class method. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin ADVANCING WITH RAILS July 21-24 Edison, NJ See http://www.rubypal.com for details and updates!