def event_callback(*methods)
      methods.each do |method|
        module_eval <<-EOD
          remove_method "#{method}"
          def #{method}(*args, &block)
            if block
              @#{method}_callback = block
              return
            end

            if defined? @#{method}_callback and @#{method}_callback
              @#{method}_callback.call(*args)
            end
          end
        EOD
      end
    end
def event_callback(*methods)
      methods.each do |method|
        module_eval <<-EOD
          remove_method "#{method}"
          def #{method}(*args, &block)
            if block
              @#{method}_callback = block
              return
            end

            if defined? @#{method}_callback and @#{method}_callback
              @#{method}_callback.call(*args)
            end
          end
        EOD
      end
    end
Define callbacks whose behavior can be changed on-the-fly per instance.
 This is done by giving a block to the callback method, which is captured
 as a proc and stored for later.  If the method is called without a block,
 the stored block is executed if present, otherwise it's a noop.