Sha256: 32a51ab635d483a69c3f01c2f81939ce563e2a7652b1b1b174289ceac507aacb

Contents?: true

Size: 592 Bytes

Versions: 1

Compression:

Stored size: 592 Bytes

Contents

module Ray
  class Joystick
    @@joysticks = Hash.new { |h, k| h[k] = new(k) }

    class << self
      # @return [Ray::Joystick] an opened joystick
      def [](id)
        joy = @@joysticks[id]
        joy.open if joy.closed?
        joy
      end

      # Enumerates through all the joysitcks.
      #
      # @yield [joystick]
      # @yieldparam [Ray::Joystick] joystick
      def each
        return Enumerator.new(self, :each) unless block_given?

        (0...count).each do |i|
          yield self[i]
        end

        self
      end

      include Enumerable
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ray-0.0.1 lib/ray/joystick.rb