From: nobu.nokada@... Date: 2002-02-19T16:03:33+09:00 Subject: Re: Anonymous class support Hi, At Tue, 19 Feb 2002 10:33:31 +0900, David Corbin wrote: > I find Java anonymous classes to be very helpful when writing UnitTests, > because I can overide a method for "one time use" just to verify it gets > called correctly. > > I realize that I can write a new class that responds to whatever methods > I need. But I'm talking about the syntactic convenience of defining > the method as part of the the new call. > > Does Ruby have support for anything like this? As written already, you can use blocks, singleton methods, and anonymous class with Class.new like: Class.new(superclass).class_eval do def foo end end In 1.7, .class_eval isn't necessary. -- Nobu Nakada