From 4015a301cc0268cfcfef4209a9841a8c74f6a538 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sat, 18 Apr 2015 03:09:16 +0000 Subject: [PATCH] Refactor Workers::Base callback definitions --- lib/uh/wm/workers/base.rb | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/uh/wm/workers/base.rb b/lib/uh/wm/workers/base.rb index 2c2e63b..6f1d5f3 100644 --- a/lib/uh/wm/workers/base.rb +++ b/lib/uh/wm/workers/base.rb @@ -10,20 +10,12 @@ module Uh @ios << io end - def before_wait &block - if block_given? then @before_wait = block else @before_wait end - end - - def on_timeout &block - if block_given? then @on_timeout = block else @on_timeout end - end - - def on_read &block - if block_given? then @on_read = block else @on_read end - end - - def on_read_next &block - if block_given? then @on_read_next = block else @on_read_next end + %w[before_wait on_timeout on_read on_read_next].each do |m| + class_eval <<-eoh + def #{m} &block + if block_given? then @#{m} = block else @#{m} end + end + eoh end end end