<p>The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object instance. Although I know how to code the singleton pattern in C++ and Java, I was wondering if anyone know how to implement it in Ruby?</p>

[{'answer_id': 4686, 'author': 'cynicalman', 'author_id': 410, 'author_profile': 'https://Stackoverflow.com/users/410', 'pm_score': 3, 'selected': False, 'text': '<p>Use the singleton module:</p>\n\n<pre><code>class Clazz\n  include Singleton\nend\n</code></pre>\n\n<p>See <a href="http://www.ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html" rel="noreferrer">http://www.ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html</a> for more info.</p>\n'}, {'answer_id': 5453, 'author': 'CodingWithoutComments', 'author_id': 25, 'author_profile': 'https://Stackoverflow.com/users/25', 'pm_score': 4, 'selected': True, 'text': "<p>Actually, the above answer was not completely correct.</p>\n\n<pre><code>require 'singleton'\n\nclass Example\n  include Singleton\nend\n</code></pre>\n\n<p>You also need to include the require 'singleton' statement.</p>\n"}, {'answer_id': 5592, 'author': 'Michael Neale', 'author_id': 699, 'author_profile': 'https://Stackoverflow.com/users/699', 'pm_score': 0, 'selected': False, 'text': '<p>You could use modules to the same effect I believe, although its not "the singleton pattern" you can have global state that way (which is what a singleton is ! Naughty global state !).</p>\n'}]
['https://Stackoverflow.com/questions/4677', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/25/']