From: gwtmp01@... Date: 2005-12-29T14:43:34+09:00 Subject: Re: Locking classes? On Dec 29, 2005, at 12:04 AM, Steve Litt wrote: > Yeah, on a similar subject, under what circumstances would one want > to add a > method to an object if that method wasn't part of its class? I'm going to use the term 'singleton method' to mean a method associated with a single object. Creating a singleton method on a class object is the idiom for creating 'class methods' in Ruby. For example consider Date.today. It doesn't make sense to define the method 'today' in class 'Class' because we don't want *all* classes to respond to 'today' but just one particular class known as 'Date'. So we make Date.today a singleton method on the class object known as 'Date'. Another common use of singleton methods is to override a method definition for one particular object. In other languages this might be accomplished by explicitly defining a subclass with the new method definition and then creating an instance. In Ruby, you create a regular instance of the base class and then define a singleton method to override the definition from the class. Gary Wright