Class: Bulldog::Vector2

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldog/vector2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Vector2

Returns a new instance of Vector2.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bulldog/vector2.rb', line 3

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

Instance Attribute Details

#xObject

Returns the value of attribute x.



16
17
18
# File 'lib/bulldog/vector2.rb', line 16

def x
  @x
end

#yObject

Returns the value of attribute y.



16
17
18
# File 'lib/bulldog/vector2.rb', line 16

def y
  @y
end