Singletons in Ruby

programming Ruby ruby singleton patterns

require 'singleton'

class MySingletonClass
  include Singleton
end

MySingletonClass.instance   #=> the singleton instance
MySingletonClass.new        #=> NoMethodError

I love dynamic languages.

See Ruby’s Singleton module for more information.