### Home Classes Methods

### In Files

- lib/rubygame/event_actions.rb

### Parent

Object

### Methods

- ::new
- #perform

### Files

- CREDITS
- LICENSE
- NEWS
- README
- ROADMAP
- custom_sdl_load_paths.rdoc
- getting_started.rdoc
- keyboard_symbols.rdoc
- macosx_install.rdoc
- managing_framerate.rdoc
- surface_palettes.rdoc
- windows_install.rdoc

### Class/Module Index

Quicksearch

- Rubygame
- Rubygame::ActiveEvent
- Rubygame::Clock
- Rubygame::Color
- Rubygame::Color::ColorBase
- Rubygame::Color::ColorHSL
- Rubygame::Color::ColorHSV
- Rubygame::Color::ColorRGB
- Rubygame::Color::Palette
- Rubygame::Event
- Rubygame::EventActions
- Rubygame::EventActions::BlockAction
- Rubygame::EventActions::MethodAction
- Rubygame::EventActions::MultiAction
- Rubygame::EventHandler
- Rubygame::EventHandler::HasEventHandler
- Rubygame::EventHook
- Rubygame::EventQueue
- Rubygame::EventTriggers
- Rubygame::EventTriggers::AndTrigger
- Rubygame::EventTriggers::AttrTrigger
- Rubygame::EventTriggers::BlockTrigger
- Rubygame::EventTriggers::InstanceOfTrigger
- Rubygame::EventTriggers::KeyPressTrigger
- Rubygame::EventTriggers::KeyReleaseTrigger
- Rubygame::EventTriggers::KindOfTrigger
- Rubygame::EventTriggers::MouseMoveTrigger
- Rubygame::EventTriggers::MousePressTrigger
- Rubygame::EventTriggers::MouseReleaseTrigger
- Rubygame::EventTriggers::OrTrigger
- Rubygame::EventTriggers::TickTrigger
- Rubygame::EventTriggers::YesTrigger
- Rubygame::Events
- Rubygame::Events::ClockTicked
- Rubygame::Events::InputFocusGained
- Rubygame::Events::InputFocusLost
- Rubygame::Events::JoystickAxisMoved
- Rubygame::Events::JoystickBallMoved
- Rubygame::Events::JoystickButtonEvent
- Rubygame::Events::JoystickButtonPressed
- Rubygame::Events::JoystickButtonReleased
- Rubygame::Events::JoystickHatMoved
- Rubygame::Events::KeyPressed
- Rubygame::Events::KeyReleased
- Rubygame::Events::KeyboardEvent
- Rubygame::Events::MouseButtonEvent
- Rubygame::Events::MouseFocusGained
- Rubygame::Events::MouseFocusLost
- Rubygame::Events::MouseMoved
- Rubygame::Events::MousePressed
- Rubygame::Events::MouseReleased
- Rubygame::Events::QuitRequested
- Rubygame::Events::WindowExposed
- Rubygame::Events::WindowMinimized
- Rubygame::Events::WindowResized
- Rubygame::Events::WindowUnminimized
- Rubygame::ExposeEvent
- Rubygame::Ftor
- Rubygame::GL
- Rubygame::Hotspot
- Rubygame::JoyAxisEvent
- Rubygame::JoyBallEvent
- Rubygame::JoyDownEvent
- Rubygame::JoyHatEvent
- Rubygame::JoyUpEvent
- Rubygame::Joystick
- Rubygame::Key
- Rubygame::KeyDownEvent
- Rubygame::KeyUpEvent
- Rubygame::MailQueue
- Rubygame::MediaBag
- Rubygame::Mixer
- Rubygame::Mixer::Music
- Rubygame::Mixer::Sample
- Rubygame::Mouse
- Rubygame::MouseDownEvent
- Rubygame::MouseMotionEvent
- Rubygame::MouseUpEvent
- Rubygame::Music
- Rubygame::NamedResource
- Rubygame::NamedResource::NamedResourceClassMethods
- Rubygame::QuitEvent
- Rubygame::Rect
- Rubygame::ResizeEvent
- Rubygame::SDLError
- Rubygame::SFont
- Rubygame::Screen
- Rubygame::Sound
- Rubygame::Sprites
- Rubygame::Sprites::DepthSortGroup
- Rubygame::Sprites::Group
- Rubygame::Sprites::LimitGroup
- Rubygame::Sprites::Sprite
- Rubygame::Sprites::UpdateGroup
- Rubygame::Surface
- Rubygame::TTF

No matching classes.

# Rubygame::EventActions::BlockAction

BlockAction is an event action used with EventHook. BlockAction takes a code block at initialization. When the action is performed, it executes the block, passing in the EventHook#owner and the event that is being handled as the two parameters to the block.

Example:

    hit_by_missile = KindOfTrigger.new( MissileCollisionEvent )

    take_damage = BlockAction.new { |owner, event|
      owner.health -= event.damage_amount
    }

    hook = EventHook.new( :owner   => player_ship,
                          :trigger => hit_by_missile,
                          :action  => take_damage )

NOTE: It is also possible to pass a Proc or detached Method as the block, using the standard Ruby syntax for that:

    # Using a pre-built Proc.

    my_proc = Proc.new { |owner, event| do_something() }

    BlockAction.new( &my_proc )

    # Using a detached method.

    def a_method( owner, event )
      do_something
    end

    detached_method = method(:a_method)

    BlockAction.new( &detached_method )

### Public Class Methods

new( &block ) click to toggle source

Create a new BlockAction using the given code block.

&block | the code block to execute. Should take two parameters, owner and event. (Proc, required)
May raise | ArgumentError, if no block is provided.

    # File lib/rubygame/event_actions.rb, line 100
    def initialize( &block )
            raise ArgumentError, "BlockAction needs a block" unless block_given?
            @block = block
    end

### Public Instance Methods

perform( owner, event ) click to toggle source

Execute the code block, passing in owner and event as the two parameters to the block. This is automatically called by EventHook when an event matches the trigger. You should usually not call it in your own code.

owner | the owner of the EventHook, or nil if there is none. (Object, required)
event | the event that matched the trigger. (Object, required)

    # File lib/rubygame/event_actions.rb, line 114
    def perform( owner, event )
            @block.call( owner, event )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.