Parent

Methods

Class/Module Index [+]

Quicksearch

Rubygame::EventTriggers::AttrTrigger

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.

Public Class Methods

new( attributes ) click to toggle source

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 )
# File lib/rubygame/event_triggers.rb, line 193
def initialize( attributes )
        @attributes = attributes
end

Public Instance Methods

match?( event ) click to toggle source

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.

# 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]

Generated with the Darkfish Rdoc Generator 2.