From 1ba1247b7f83a93772d4f2e3696a1ba9064a9f26 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 3 Aug 2023 15:07:18 +0100 Subject: [PATCH] callbacks now public method register,deregister handle single callbacks or arrays of callbacks --- examples/events/main.rb | 2 +- lib/voicemeeter/event.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/events/main.rb b/examples/events/main.rb index 7248bdc..fb7882a 100644 --- a/examples/events/main.rb +++ b/examples/events/main.rb @@ -3,7 +3,7 @@ require_relative "../../lib/voicemeeter" class Main def initialize(vm) @vm = vm - @vm.register(method(:on_pdirty), method(:on_mdirty), method(:on_midi), method(:on_ldirty)) + @vm.register([method(:on_pdirty), method(:on_mdirty), method(:on_midi), method(:on_ldirty)]) end def run diff --git a/lib/voicemeeter/event.rb b/lib/voicemeeter/event.rb index 2af4fc2..ba7df2c 100644 --- a/lib/voicemeeter/event.rb +++ b/lib/voicemeeter/event.rb @@ -3,15 +3,17 @@ require_relative "logger" module Voicemeeter module Events module Callback - private def callbacks + def callbacks @callbacks ||= [] end - def register(*cbs) + def register(cbs) + cbs = [cbs] unless cbs.respond_to? :each cbs.each { |cb| callbacks << cb unless callbacks.include? cb } end - def deregister(*cbs) + def deregister(cbs) + cbs = [cbs] unless cbs.respond_to? :each callbacks.reject! { |cb| cbs.include? cb } end