A quick method to declare singleton belongs to.
509867
def singleton_belongs_to(*symbols, &block)
        options = symbols.extract_options!
        options.merge!(singleton: true)
        belongs_to(*symbols, options, &block)
      end
1017350
def _set_shared_instances(self):
        """"""
        self.inqueue = self.em.get_inqueue()
        self.outqueue = self.em.get_outqueue()
        self.namespace = self.em.get_namespace()
472283
def register_single(key, value, param=None):
    ''''''
    get_current_scope().container.register(key, lambda: value, param)
121473
def _register(self, cls):
        
        if not inspect.isclass(cls):
            raise ValueError('Only classes may be registered.')
        elif not issubclass(cls, self._registerable_class):
            raise ValueError('Only %s classes or subclasses may be registered.'
                             % self._registerable_class.__name__)

        if cls not in self._registry:
            cls._registered_with = self
            self._registry[cls] = cls()

        return self._registry[cls]
741348
def get_singleton(cls, annotators=None, **options):
        
        if annotators is not None:
            annotators = tuple(annotators)
        if annotators not in cls._singletons:
            cls._singletons[annotators] = cls(annotators, **options)
        return cls._singletons[annotators]
136205
def singleton(*args, **kwargs):
    '''
    
    '''

    def decorator(cls: type) -> Callable[[], object]:
        if issubclass(type(cls), _SingletonMetaClassBase):
            raise TypeError('cannot inherit from another singleton class.')

        box = _Box()
        factory = None
        lock = Lock()

        def metaclass_call(_):
            if box.value is None:
                with lock:
                    if box.value is None:
                        instance = cls(*args, **kwargs)
                        instance.__class__ = factory
                        box.value = (instance, ) # use tuple to handle `cls()` return `None`
            return box.value[0]

        def _is_init(*_):
            return box.value is not None

        SingletonMetaClass = type('SingletonMetaClass', (type(cls), _SingletonMetaClassBase), {
            '__slots__': (),
            '__call__': metaclass_call
        })

        factory = SingletonMetaClass(cls.__name__, (cls, ), {
            '__slots__': (),
            '_is_init': _is_init
        })
        return update_wrapper(factory, cls, updated=())

    return decorator
888717
def singleton(cls):
    
    import inspect

    # Create a structure to store instances of any singletons that get
    # created.
    instances = {}

    # Make sure that the constructor for this class doesn't take any
    # arguments.  Since singletons can only be instantiated once, it doesn't
    # make any sense for the constructor to take arguments.  If the class 
    # doesn't implement its own constructor, don't do anything.  This case is 
    # considered specially because it causes a TypeError in python 3.3 but not 
    # in python 3.4.
    if cls.__init__ is not object.__init__:
        argspec = inspect.getfullargspec(cls.__init__)
        if len(argspec.args) != 1 or argspec.varargs or argspec.varkw:
            raise TypeError("Singleton classes cannot accept arguments to the constructor.")


    def get_instance():
        """ Creates and returns the singleton object.  This function is what 
        gets returned by this decorator. """

        # Check to see if an instance of this class has already been
        # instantiated.  If it hasn't, create one.  The `instances` structure
        # is technically a global variable, so it will be preserved between
        # calls to this function.
        if cls not in instances:
            instances[cls] = cls()

        # Return a previously instantiated object of the requested type.
        return instances[cls]

    # Return the decorator function.
    return get_instance
688068
public static function singleton()
    {
        if (!isset(self::$_instance)) {
            $c = __CLASS__;
            self::$_instance = new $c;
        }

        return self::$_instance;
    }
294605
def register(self, cls, instance):
        
        if not issubclass(cls, DropletInterface):
            raise TypeError('Given class is not a NAZInterface subclass: %s'
                            % cls)

        if not isinstance(instance, cls):
            raise TypeError('Given instance does not implement the class: %s'
                            % instance)

        if instance.name in self.INSTANCES_BY_NAME:
            if self.INSTANCES_BY_NAME[instance.name] != instance:
                raise ValueError('Given name is registered '
                                 'by other instance: %s' % instance.name)

        self.INSTANCES_BY_INTERFACE[cls].add(instance)
        self.INSTANCES_BY_NAME[instance.name] = instance
1101563
public static function singleton()
    {
        $returnValue = null;

        if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c();
		}
		$returnValue = self::$instance;



        return $returnValue;
    }
561075
def define_property(property, value)
      define_singleton_method(property) { value }

      if value == true || value == false
        define_singleton_method("#{property}?") { value }
      end
    end
496876
def singleton(klass):
    
    instances = {}

    def getinstance(*args, **kwargs):
        if klass not in instances:
            instances[klass] = klass(*args, **kwargs)
        return instances[klass]
    return wraps(klass)(getinstance)
882762
public static function singleton() {
        $returnValue = null;

        
        $serviceName = get_called_class();
        if (!isset(self::$instances[$serviceName])) {
            self::$instances[$serviceName] = new $serviceName();
        }

        $returnValue = self::$instances[$serviceName];
        

        return $returnValue;
    }
14273
public Object[] singletonArray(Object value) {
        Object[] result = new Object[1];
        result[0] = value;
        return result;
    }
161316
def singleton(cls):
    '''
    
    '''

    cls.__new_original__ = cls.__new__

    @wraps(cls.__new__)
    def singleton_new(cls, *args, **kw):
        it = cls.__dict__.get('__it__')
        if it is not None:
            return it

        cls.__it__ = it = cls.__new_original__(cls, *args, **kw)
        it.__init_original__(*args, **kw)
        return it

    cls.__new__ = singleton_new
    cls.__init_original__ = cls.__init__
    cls.__init__ = object.__init__

    return cls
201819
public static function singleton()
    {
        $returnValue = null;

        

		if (core_kernel_persistence_smoothsql_Property::$instance == null){
			core_kernel_persistence_smoothsql_Property::$instance = new core_kernel_persistence_smoothsql_Property();
		}
		$returnValue = core_kernel_persistence_smoothsql_Property::$instance;

        

        return $returnValue;
    }
1270037
def register(self, name, obj):
        """"""
        if name in self.all:
            log.debug('register: %s already existed: %s', name, obj.name)
            # code.interact(local=locals())
            raise DuplicateDefinitionException(
                'register: %s already existed: %s' % (name, obj.name))
        log.debug('register: %s ', name)
        self.all[name] = obj
        return obj