Class: Discorb::EventHandler
- Inherits:
-
Object
- Object
- Discorb::EventHandler
- 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
-
#block ⇒ Proc
readonly
The block to be called.
-
#id ⇒ Symbol
readonly
The event id.
-
#metadata ⇒ Hash
readonly
The event metadata.
-
#once ⇒ Boolean
(also: #once?)
readonly
Whether the event is once or not.
Instance Method Summary collapse
-
#call ⇒ Object
Calls the block associated with the event.
-
#initialize(block, id, metadata) ⇒ EventHandler
constructor
A new instance of EventHandler.
- #inspect ⇒ Object
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.
11 12 13 |
# File 'lib/discorb/event_handler.rb', line 11 def block @block end |
#id ⇒ Symbol (readonly)
Returns 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.
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.
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 |