Class: RubyCord::EventHandler
- Inherits:
-
Object
- Object
- RubyCord::EventHandler
- Defined in:
- lib/rubycord/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 ⇒ String
Object class and attributes.
Constructor Details
#initialize(block, id, metadata) ⇒ EventHandler
Returns a new instance of EventHandler.
21 22 23 24 25 26 27 |
# File 'lib/rubycord/event_handler.rb', line 21 def initialize(block, id, ) @block = block @id = id @once = .fetch(:once, false) = @rescue = nil end |
Instance Attribute Details
#block ⇒ Proc (readonly)
Returns the block to be called.
12 13 14 |
# File 'lib/rubycord/event_handler.rb', line 12 def block @block end |
#id ⇒ Symbol (readonly)
Returns the event id.
14 15 16 |
# File 'lib/rubycord/event_handler.rb', line 14 def id @id end |
#metadata ⇒ Hash (readonly)
Returns the event metadata.
16 17 18 |
# File 'lib/rubycord/event_handler.rb', line 16 def end |
#once ⇒ Boolean (readonly) Also known as: once?
Returns whether the event is once or not.
18 19 20 |
# File 'lib/rubycord/event_handler.rb', line 18 def once @once end |
Instance Method Details
#call ⇒ Object
Calls the block associated with the event.
37 38 39 |
# File 'lib/rubycord/event_handler.rb', line 37 def call(...) @block.call(...) end |
#inspect ⇒ String
Returns Object class and attributes.
30 31 32 |
# File 'lib/rubycord/event_handler.rb', line 30 def inspect "#<#{self.class} @id=#{@id}" end |