Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2017 05:14
Show Gist options
  • Save anonymous/17dc0bfd1069853f7d9903a29b3ae5c4 to your computer and use it in GitHub Desktop.
Save anonymous/17dc0bfd1069853f7d9903a29b3ae5c4 to your computer and use it in GitHub Desktop.
Crystal Lang singleton
class Singleton
@@instance : Nil | Singleton
@@instance = nil
def self.new
@@instance ||= Singleton.allocate.tap(&.initialize)
@@instance.as(Singleton)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment