From: Eero Saynatkari Date: 2006-10-27T15:25:40+09:00 Subject: Re: Singleton Methods --qUZ+4mk6dr19Czgg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2006.10.27 15:15, bparanj@gmail.com wrote: > What is the purpose of singleton method? Why is singleton method > defined on individual object instead of a class? TIA That, precisely, IS the point of a singleton method: being defined for one object only. It is often useful to be able to define special behaviour for an individual object. One could imagine several things but a very good example is one that you have seen before on some instances of class Class: class Foo def self.foo=20 puts 'Yay singletons!' end end # Same as Foo =3D Class.new =20 def Foo.foo puts 'Yay singletons!' end This is how Ruby implements 'class methods' without having to=20 include any special behaviour. Just objects and singleton methods. Generally, any object-level customisation. In Ruby, a type is=20 more important than a class. --qUZ+4mk6dr19Czgg Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFFQaWy7Nh7RM4TrhIRAtF4AKDSXDpIFpafYY4BxUSQYXnI3IFs2QCgs021 5u12GbPk9sXItVC+0+8jTVM= =uGuK -----END PGP SIGNATURE----- --qUZ+4mk6dr19Czgg--