Skip to content

Instantly share code, notes, and snippets.

@ainame
Created June 6, 2013 17:19
Show Gist options
  • Save ainame/5723216 to your computer and use it in GitHub Desktop.
Save ainame/5723216 to your computer and use it in GitHub Desktop.
module SingletonClass
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def new
super
instance
end
def instance
Dispatch.once { @instance ||= alloc.init }
@instance
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment