On Tue, Nov 30, 2004 at 08:07:49PM +0000, mark sparshatt wrote: : Sam Ruby wrote: : >I know what a singleton is. I don't know what it means to "put the : >object into a singleton anonymous subclass", or why you would want to do : >such a thing. : > : : I think that this is in order to supports Ruby's feature of being able : add methods to individual objects. : : In the following code : : class A : end : : a = A.new : def a.method() : end : : this creates an anomynous subclass of A and makes a an instance of the : new class.
Perl 6 also does this if you compose a role into an object rather than into a class. You can't currently compose a method directly unless you use an anonymous role: $a = new A; $a does role { method mymethod() {...} }; (Though existing property methods may be mixed in with the "but" operator. Such roles of such properties aren't anonymous, but since Perl can intuit the role from the property name, they're effectively anonymous.) Larry