How do I create a Class using the Singleton Design Pattern in Ruby? *

Question

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?

Answer

Actually, the above answer was not completely correct.

require 'singleton'

class Example
include Singleton
end

You also need to include the require 'singleton' statement.

< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/4677/" >How do I create a Class using the Singleton Design Pattern in Ruby?< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment