Archived
1
0
Fork 0

Use Singleton

This commit is contained in:
Braiden Vasco 2017-07-31 04:41:12 +00:00
parent 0034417bdf
commit 3aeba166b2
2 changed files with 4 additions and 11 deletions

View file

@ -8,4 +8,4 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
require 'main'
Main.new
Main.instance

View file

@ -2,7 +2,7 @@
require 'tox'
require 'thread'
require 'singleton'
require 'helpers'
require 'actions'
@ -10,18 +10,11 @@ require 'reducer'
require 'screen'
class Main
include Singleton
SAVEDATA_FILENAME = File.expand_path '../savedata', __dir__
def self.inherited(_base)
raise "#{self} is final"
end
def self.mutex
(@mutex ||= Mutex.new).tap { freeze }
end
def initialize
raise "#{self.class} is singleton" unless self.class.mutex.try_lock
call
end