module Synchronizer include MonitorMixin module ClassMethods def synchronize *methods methods.each do |name| als = (name.to_s =~ /^[_a-zA-Z0-9]+$/) ? name : RubyExt::Cache.alias_counter.to_sym alias_method :"sync_#{als}", name script = "\ def #{name} *p, &b synchronize{sync_#{als} *p, &b} end" class_eval script, __FILE__, __LINE__ end end def synchronize_all methods = self.instance_methods(false).collect{|m| m.to_sym} synchronize *methods end protected def alias_counter @alias_counter += 1 return :"m#{@alias_counter}" end end end