From: Joel VanderWerf Date: 2002-02-19T14:29:43+09:00 Subject: Re: Anonymous class support 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? This isn't syntactically very simple, but maybe it does what you want: x = "hello" def x.upcase puts "upcasing..." super end puts x.upcase # ==> upcasing... # HELLO