Class: Discorb::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/event_handler.rb

Overview

Represents a event handler. This class shouldn't be instantiated directly. Use Client#on instead.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, id, metadata) ⇒ EventHandler

Returns a new instance of EventHandler.



20
21
22
23
24
25
26
# File 'lib/discorb/event_handler.rb', line 20

def initialize(block, id, )
  @block = block
  @id = id
  @once = .fetch(:once, false)
  @metadata = 
  @rescue = nil
end

Instance Attribute Details

#blockProc (readonly)

Returns the block to be called.

Returns:

  • (Proc)

    the block to be called.



11
12
13
# File 'lib/discorb/event_handler.rb', line 11

def block
  @block
end

#idSymbol (readonly)

Returns the event id.

Returns:

  • (Symbol)

    the event id.



13
14
15
# File 'lib/discorb/event_handler.rb', line 13

def id
  @id
end

#metadataHash (readonly)

Returns the event metadata.

Returns:

  • (Hash)

    the event metadata.



15
16
17
# File 'lib/discorb/event_handler.rb', line 15

def 
  @metadata
end

#onceBoolean (readonly) Also known as: once?

Returns whether the event is once or not.

Returns:

  • (Boolean)

    whether the event is once or not.



17
18
19
# File 'lib/discorb/event_handler.rb', line 17

def once
  @once
end

Instance Method Details

#callObject

Calls the block associated with the event.



35
36
37
# File 'lib/discorb/event_handler.rb', line 35

def call(...)
  @block.call(...)
end

#inspectObject



28
29
30
# File 'lib/discorb/event_handler.rb', line 28

def inspect
  "#<#{self.class} @id=#{@id}"
end