Class: Voltage::Listener
- Inherits:
-
Object
show all
- Defined in:
- lib/voltage/listener.rb
Instance Method Summary
collapse
Constructor Details
#initialize(context, type, event, &block) ⇒ Listener
Returns a new instance of Listener.
5
6
7
8
9
10
11
|
# File 'lib/voltage/listener.rb', line 5
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
13
14
15
16
17
|
# File 'lib/voltage/listener.rb', line 13
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
23
24
25
|
# File 'lib/voltage/listener.rb', line 23
def respond_to_missing?(method_name, _include_private)
method_name == @event_method
end
|
#to_s ⇒ Object
19
20
21
|
# File 'lib/voltage/listener.rb', line 19
def to_s
"<#{self.class} event: #{@event_method}>"
end
|