Method: Rubygame::MailQueue#subscribe

Defined in:
lib/rubygame/queue.rb

#subscribe(client, klass) ⇒ Object

Subscribe client to receive events that match klass.

After the client object has been subscribed, the MailQueue will push along any event for which “klass === event” is true. This usually means that the event is an instance of klass or one of klass’s child classes; however, note that klass may have changed its own #=== operator to have different behavior, so this is not always the case.

Important: the MailQueue uses the client’s #push method to deliver events! If the client does not have such a method, MailQueue will silently catch the error and move on to the next client.

A client object may be subscribed for many different types of events simultaneously, and more than one client object may be subscribed to any type of event (in which case each object will receive the event). A client may also be subscribed multiple times for the same type (in which case it will receive duplicate events). Likewise, the client will receive duplicates if it is subscribed to multiple classes which share ancestry, for example Numeric and Float.

If a client wishes to receive ALL types of events, it can subscribe to Object, which is a parent class of all objects.

If the queue’s @autodeliver is true, it will deliver events to subscribers immediately after they are posted, rather than waiting for #deliver to be called.



246
247
248
249
250
# File 'lib/rubygame/queue.rb', line 246

def subscribe(client,klass)
  @subscribe[klass] << client
rescue NoMethodError
  @subscribe[klass] = [client] if @subscribe[klass].nil?
end