Class: Hark::Listener

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

Overview

A Listener holds a dispatcher, which it dispatches messages to

A listener is by default a ‘strict’ listener, it will raise NoMethodError if it is sent a message it doesn’t know how to handle.

A listener can be turned into a ‘lax’ listener, by sending it the #lax message. A lax listener will silently swallow any unknown messages.

Direct Known Subclasses

LaxListener, StrictListener

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Listener

Returns a new instance of Listener.



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

def initialize(*args, &block)
  @dispatcher = Dispatcher.from(*args, &block)
  freeze
end

Instance Attribute Details

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



14
15
16
# File 'lib/hark/listener.rb', line 14

def dispatcher
  @dispatcher
end

Class Method Details

.new(*args, &block) ⇒ Object



10
11
12
# File 'lib/hark/listener.rb', line 10

def self.new *args, &block
  self == Listener ? StrictListener.new(*args, &block) : super(*args, &block)
end

Instance Method Details

#hark(*args, &block) ⇒ Object



29
30
31
# File 'lib/hark/listener.rb', line 29

def hark *args, &block
  self.class.new dispatcher, *args, &block
end

#laxObject



25
26
27
# File 'lib/hark/listener.rb', line 25

def lax
  LaxListener.new dispatcher
end

#strictObject



21
22
23
# File 'lib/hark/listener.rb', line 21

def strict
  StrictListener.new dispatcher
end