Module: Nova::Starbound::DefaultBehavior::Eventable::ClassMethods
- Included in:
- Nova::Starbound::DefaultBehavior
- Defined in:
- lib/nova/starbound/default_behavior/eventable.rb
Overview
Class methods.
Instance Method Summary collapse
-
#handle(type, meth = nil) {|packet, protocol| ... } ⇒ void
Defines how to handle a specific type of packet.
-
#handles ⇒ Hash
The handles for events that are defined on this class.
Instance Method Details
#handle(type, meth = nil) {|packet, protocol| ... } ⇒ void
If a block isn’t used, the method should accept two arguments (see yield params for the arguments).
This method returns an undefined value.
Defines how to handle a specific type of packet. The method of handling a packet can be defined in 3 ways: first, if a method name (second argument) is given, that method is used to handle the packet. Second, if a block is given, that block is used. And last, if neither of them are provided, the method name is assumed from the struct type and packet type in the format handle_<struct>_<packet>. The given method can and should be private.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nova/starbound/default_behavior/eventable.rb', line 31 def handle(type, meth = nil, &block) struct = type.keys.first packet = type.values.first proc = nil if meth proc = meth elsif block_given? proc = block else proc = :"handle_#{struct}_#{packet}" end handles[{struct => packet}] = proc end |
#handles ⇒ Hash
The handles for events that are defined on this class.
51 52 53 |
# File 'lib/nova/starbound/default_behavior/eventable.rb', line 51 def handles @handles ||= {} end |