Class Rubygame::EventTriggers::AttrTrigger
In: lib/rubygame/event_triggers.rb
Parent: Object

AttrTrigger is an event trigger which fires when an event has the expected value(s) for one or more attributes.

AttrTrigger stores a Hash of :attr => value pairs, and checks each event to see if event.attr returns value. If all attributes have the expected value, the trigger fires.

Methods

match?   new  

Public Class methods

Initialize a new instance of AttrTrigger with a Hash of one or more :attr => value pairs.

attributes:The attributes / value pairs to check. (Hash, required)

Example:

  # Matches if event.color returns :red and
  # event.size returns :big
  AttrTrigger.new( :color => :red, :size => :big )

[Source]

# File lib/rubygame/event_triggers.rb, line 193
        def initialize( attributes )
                @attributes = attributes
        end

Public Instance methods

Returns true if, for every :attr => value pair, the event responds to :attr and calling event.attr returns value.

Returns false if any of the attributes is not the expected value.

[Source]

# File lib/rubygame/event_triggers.rb, line 202
        def match?( event )
                @attributes.all? { |key, value|
                        event.respond_to?(key) and (event.send(key) == value)
                }
        end

[Validate]