From 3aeba166b2ffd68b307df2b3f278097722f3a1ed Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 31 Jul 2017 04:41:12 +0000 Subject: [PATCH] Use Singleton --- exe/toxon | 2 +- lib/main.rb | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/exe/toxon b/exe/toxon index 42941d0..97f22d9 100755 --- a/exe/toxon +++ b/exe/toxon @@ -8,4 +8,4 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib require 'main' -Main.new +Main.instance diff --git a/lib/main.rb b/lib/main.rb index 39781fb..f2eac2d 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -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