From: Nathaniel Talbott Date: 2003-08-02T18:13:55+09:00 Subject: Anonymous, single instance class creation I find myself doing the following in tests a lot: some_external_object = Object.new def some_external_object.some_method ... do some stuff ... end OR: some_external_object = Object.new class << some_external_object def some_method ... do some stuff ... end end Is there a way to do that more concisely? Perhaps to eliminate the separate Object.new? Also, is there a way to let the methods be more like closures, i.e.: a = "stuff" some_external_object = Object.new def some_external_object.some_method a #from external scope end assert_equal(a, method_under_test(some_external_object)) That would make it even more powerful. To explain why I care: I'm finding this technique to be clearer than using an explicit mocking framework. It tends to help me keep the stubs simple, and it makes it explicit in the test (or sometimes I pull it out in to #setup) what's going on, as opposed to having to look at another class to see everything that makes the test tick. There are definitely downsides, but if there are good answers to the two questions above, perhaps not as many as I thought. Thanks! Nathaniel <:((><