Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
Singleton library for Crystal. Created out of necessity to work around the problem with class variables inside of generic classes.
Add this to your application's shard.yml
:
dependencies:
singleton:
github: waterlink/singleton.cr
require "singleton"
Singleton::Of(Example).instance
This uses Example.new
to produce the instance.
Making singleton out of Example(T)
class now would look like that:
class Example(T)
def self.instance
Singleton::Of(self).instance
end
end
Singleton.reset