Class: Bulldog::Vector2
- Inherits:
-
Object
- Object
- Bulldog::Vector2
- Defined in:
- lib/bulldog/vector2.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(object) ⇒ Vector2
constructor
A new instance of Vector2.
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
#x ⇒ Object
Returns the value of attribute x.
16 17 18 |
# File 'lib/bulldog/vector2.rb', line 16 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
16 17 18 |
# File 'lib/bulldog/vector2.rb', line 16 def y @y end |