Class: SDL2::Joystick::Components

Inherits:
Object
  • Object
show all
Defined in:
lib/sdl2/joystick/components.rb

Overview

Abstract component enumerator Requires :count and :[] to be defined

Direct Known Subclasses

Axes, Balls, Buttons, Hats

Instance Method Summary collapse

Constructor Details

#initialize(for_joystick) ⇒ Components

Initialize an enumeration



11
12
13
14
# File 'lib/sdl2/joystick/components.rb', line 11

def initialize(for_joystick)
  @joystick = for_joystick
  raise "Must be an SDL2::Joystick, not a #{@joystick.class.to_s}" unless @joystick.kind_of?(SDL2::Joystick)
end

Instance Method Details

#each(&block) ⇒ Object

Generate enumerator, captures all at call time



18
19
20
# File 'lib/sdl2/joystick/components.rb', line 18

def each(&block)
  count.times.map{|idx|self[idx]}.each(&block)
end