Sha256: d5bc37756f4fef28f01efa7649a2efa2f5db528c34e2b1b7f928bafac1ab1243

Contents?: true

Size: 476 Bytes

Versions: 22

Compression:

Stored size: 476 Bytes

Contents

module Bulldog
  class Vector2
    def initialize(object)
      case object
      when Array
        @x, @y = object[0].to_i, object[1].to_i
      when String
        match = /([+-]?\d+)[^-+\d]*([+-]?\d+)/.match(object) or
          raise ArgumentError, "invalid vector: #{object.inspect}"
        @x, @y = match[1].to_i, match[2].to_i
      else
        raise ArgumentError, "cannot convert to vector: #{object.inspect}"
      end
    end

    attr_accessor :x, :y
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bulldog-0.2.4 lib/bulldog/vector2.rb
bulldog-0.2.3 lib/bulldog/vector2.rb
bulldog-0.2.2 lib/bulldog/vector2.rb
bulldog-0.2.1 lib/bulldog/vector2.rb
bulldog-0.2.0 lib/bulldog/vector2.rb
bulldog-0.1.1 lib/bulldog/vector2.rb
bulldog-0.1.0 lib/bulldog/vector2.rb
bulldog-0.0.15 lib/bulldog/vector2.rb
bulldog-0.0.14 lib/bulldog/vector2.rb
bulldog-0.0.13 lib/bulldog/vector2.rb
bulldog-0.0.12 lib/bulldog/vector2.rb
bulldog-0.0.11 lib/bulldog/vector2.rb
bulldog-0.0.10 lib/bulldog/vector2.rb
bulldog-0.0.9 lib/bulldog/vector2.rb
bulldog-0.0.8 lib/bulldog/vector2.rb
bulldog-0.0.7 lib/bulldog/vector2.rb
bulldog-0.0.6 lib/bulldog/vector2.rb
bulldog-0.0.5 lib/bulldog/vector2.rb
bulldog-0.0.3 lib/bulldog/vector2.rb
bulldog-0.0.4 lib/bulldog/vector2.rb