0.0
No commit activity in last 3 years
No release in over 3 years
Tiny Singleton is a very simple implementation of the Singleton Design Pattern. Compared to the Singleton module in the stdlib, one does not need to class 'klass.instance' to get access to the singleton object, one can call 'klass.new' as usual. It is thus easier to add the Singleton Pattern to an existing class without changing the way the code calls it.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
~> 0.8
 Project Readme

tiny_singleton

Gem Version Ruby test result Build Status

Description

Tiny Singleton is a very simple implementation of the Singleton Design Pattern. Compared to the Singleton module in the stdlib, one does not need to call 'klass.instance' to get access to the singleton object, one can call 'klass.new' as usual. It is thus easier to add the Singleton Pattern to an existing class without changing the way the code calls it.

Features

Very simple implementation, relying only on Module#prepend

Examples

require 'tiny_singleton'

class Foo
  prepend TinySingleton
  def initialize(foo)
    @foo=foo
  end
end

foo=Foo.new("foo")
bar=Foo.new("bar")
foo.object_id == bar.object_id #=> true

Requirements

It needs at least ruby 2.0 since it relies on Module#prepend

Install

~~~ sh
$ gem install tiny_singleton
~~~

Copyright

Copyright © 2015–2017 Damien Robert

MIT License. See LICENSE.txt for details.