class EventMachine::Ssh::Callbacks::Callback

Attributes

block[R]

The block to call when the event is fired

event[R]
Sybmol

the name of the event

obj[R]

The object that keeps this callback

Public Class Methods

new(obj, event, &blk) click to toggle source
# File lib/em-ssh/callbacks.rb, line 76
def initialize(obj, event, &blk)
  raise ArgumentError.new("a block is required") unless block_given?
  @obj   = obj
  @event = event
  @block = blk
end

Public Instance Methods

call(*args) click to toggle source

Call the callback with optional arguments

# File lib/em-ssh/callbacks.rb, line 84
def call(*args)
  block.call(*args)
end
cancel() click to toggle source
# File lib/em-ssh/callbacks.rb, line 94
def cancel
  raise "#{@obj} does not have any callbacks for #{@event.inspect}" unless @obj.respond_to?(:callbacks) && @obj.callbacks.respond_to?(:[]) && @obj.callbacks[@event].respond_to?(:delete)
  @obj.callbacks[@event].delete(self)
  @obj = nil
  self
end
register() click to toggle source

Registers the callback with the object. This is useful if you cancel the callback at one point and want to re-enable it later on.

# File lib/em-ssh/callbacks.rb, line 90
def register
  @obj.on(self)
end