/** 
 * Enables the creation of singleton classes. This can only generate one instance.
 * @author Ariel Flesler
 */

// name is the static method of the class to retrieve the instance
// if just true is passed, the default is used: getInstance.
Class.extensions( 'singleton', function( data, name ){
	if( !name )
		return;
	if( name == true )
		name = 'getInstance';
		
	var instance, 
		old = data.c;
	
	data.c = function(){
		if( !instance ){
			if( !(this instanceof data.c) )
				return new data.c;
			instance = this;
			old.call(this);
		}
		return instance;
	};
	data.s[name] = function(){
		return this();
	};
});