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>
0 comments:
Post a Comment