title: What is the correct way of ensuring a single instance of a class?
body: <p>In java I would create something like this:</p>
  
  <pre><code>private static MyClass instance;
  
  public static MyClass getInstance() {
    if(instance != null) {
      return instance;
    }
    instance = new MyClass();
    return instance;
  }
  </code></pre>
  
  <p>What is the appropriate way to obtain the same functionality in ruby?</p>
  
  <p>Update: I've read about 'include Singleton' but when I tried to do it in irb on Ruby 1.9 I got:</p>
  
  <pre><code>[vertis@raven:~/workspace/test]$ ruby -v
  ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin9.4.0]
  [vertis@raven:~/workspace/test]$ irb
  irb(main):001:0&gt; class TestTest
  irb(main):002:1&gt;   include Singleton
  irb(main):003:1&gt; end
  NameError: uninitialized constant TestTest::Singleton
      from (irb):2:in `&lt;class:TestTest&gt;'
      from (irb):1
      from /usr/local/bin/irb:12:in `&lt;main&gt;'
  </code></pre>