Join the DZone community and get the full member experience.Join For Free
Method 1: Two classes. The first implements the functionality. The second gets the protection, i.e. it is the Singleton.
require 'singleton' class WorkingFoo # all the functionality end class SingleFoo < WorkingFoo implements Singleton endIn production use the second class, SigleFoo. For testing use the first class, WorkingFoo. Literature: Russ Olso, Design Paterns in Ruby, 2007 Method 2: If you don't own the code or if you fear missuse of the baseclass you can use metaprogramming. Ian White poposes a #reset_instance method
require 'singleton' class <
More Info: http://blog.ardes.com/2006/12/11/testing-singletons-with-ruby