Module: Discorb::Extension Abstract
- Defined in:
- lib/discorb/extension.rb
Overview
This module is abstract.
Module to make extension. extend this module to make your own extension.
Instance Attribute Summary collapse
-
#events ⇒ Hash{Symbol => Array<Discorb::Event>}
readonly
The events of the extension.
Instance Method Summary collapse
-
#event(event_name, id: nil, **discriminator, &block) ⇒ Discorb::Event
Define a new event.
-
#once_event(event_name, id: nil, **discriminator, &block) ⇒ Discorb::Event
Define a new once event.
Instance Attribute Details
#events ⇒ Hash{Symbol => Array<Discorb::Event>} (readonly)
Returns The events of the extension.
48 49 50 |
# File 'lib/discorb/extension.rb', line 48 def events @events end |
Instance Method Details
#event(event_name, id: nil, **discriminator, &block) ⇒ Discorb::Event
Define a new event.
24 25 26 27 28 29 30 31 |
# File 'lib/discorb/extension.rb', line 24 def event(event_name, id: nil, **discriminator, &block) raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol) raise ArgumentError, "block must be a Proc" unless block.is_a?(Proc) @events[event_name] ||= [] discriminator[:extension] = self.name @events[event_name] << Discorb::Event.new(block, id, discriminator) end |
#once_event(event_name, id: nil, **discriminator, &block) ⇒ Discorb::Event
Define a new once event.
43 44 45 |
# File 'lib/discorb/extension.rb', line 43 def once_event(event_name, id: nil, **discriminator, &block) event(event_name, id: id, once: true, **discriminator, &block) end |