DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Singleton In Ruby

10.07.2006
| 4421 views |
  • submit to reddit
        // simple singleton

class Singleton 
  private_class_method :new
  @@singleton = nil
  
  def Singleton.create
    @@singleton = new unless @@singleton
    @@singleton
  end
end
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:29pm

See http://ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html