Class: Signal::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/signal/listener.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, type, event, &block) ⇒ Listener

Returns a new instance of Listener.



3
4
5
6
7
8
9
# File 'lib/signal/listener.rb', line 3

def initialize(context, type, event, &block)
  @context = context
  @type = type
  @event = event
  @block = block
  @event_method = :"#{@type}_#{@event}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



11
12
13
14
# File 'lib/signal/listener.rb', line 11

def method_missing(method_name, *args)
  return super unless respond_to_missing?(method_name, false)
  @block.call(*args)
end

Instance Method Details

#respond_to_missing?(method_name, include_private) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/signal/listener.rb', line 20

def respond_to_missing?(method_name, include_private)
  method_name == @event_method
end

#to_sObject



16
17
18
# File 'lib/signal/listener.rb', line 16

def to_s
  "<#{self.class} event: #{@event_method}>"
end