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

#block -> Proc (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

#id -> Symbol (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

#metadata -> Hash (readonly)

Returns the event metadata.

Returns:

  • (Hash)

    the event metadata.



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

def 
  @metadata
end

#once -> Boolean (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

#call -> Object

Calls the block associated with the event.



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

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

#inspect -> Object



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

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