def synchronize_all_methods
      methods = self.class.instance_methods - self.class.superclass.instance_methods

      methods.each do |method_name|
        old_method = :"old_#{method_name}"
        new_method = :"synchronized_#{method_name}"

        self.class.__send__(:alias_method, old_method, method_name)

        self.class.send(:define_method, new_method) do |*args|
          @lock.synchronize { __send__(old_method, *args) }
        end

        self.class.__send__(:alias_method, method_name, new_method)
      end
    end
def synchronize_all_methods
      methods = self.class.instance_methods - self.class.superclass.instance_methods

      methods.each do |method_name|
        old_method = :"old_#{method_name}"
        new_method = :"synchronized_#{method_name}"

        self.class.__send__(:alias_method, old_method, method_name)

        self.class.send(:define_method, new_method) do |*args|
          @lock.synchronize { __send__(old_method, *args) }
        end

        self.class.__send__(:alias_method, method_name, new_method)
      end
    end
Get all public methods that were defined on this class and wrap them with
 synchronization locks so we ensure the output isn't interleaved amongst
 the various threads.