Class: Signals::BlockListener

Inherits:
Object
  • Object
show all
Defined in:
lib/signals/block_listener.rb

Overview

This is a Listener that once instantiated, will define a method that is named what is passed as the action.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, &block) ⇒ BlockListener

Returns a new instance of BlockListener.



8
9
10
11
# File 'lib/signals/block_listener.rb', line 8

def initialize(event, &block)
  @listener = block
  @event = event
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



6
7
8
# File 'lib/signals/block_listener.rb', line 6

def event
  @event
end

#listenerObject (readonly)

Returns the value of attribute listener.



6
7
8
# File 'lib/signals/block_listener.rb', line 6

def listener
  @listener
end

Instance Method Details

#call(event, *args) ⇒ Object



13
14
15
16
17
# File 'lib/signals/block_listener.rb', line 13

def call(event, *args)
  if self.event == event
    self.listener.call(*args)
  end
end