Class: Position
- Inherits:
-
Object
- Object
- Position
- Defined in:
- lib/position.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #*(scale) ⇒ Object
- #+(position) ⇒ Object
- #-(position) ⇒ Object
- #eql?(position) ⇒ Boolean (also: #==)
-
#initialize(x, y, z) ⇒ Position
constructor
A new instance of Position.
- #to_s ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Position
Returns a new instance of Position.
5 6 7 8 9 |
# File 'lib/position.rb', line 5 def initialize (x,y,z) @x=x @y=y @z=z end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/position.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/position.rb', line 3 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
3 4 5 |
# File 'lib/position.rb', line 3 def z @z end |
Instance Method Details
#*(scale) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/position.rb', line 38 def *(scale) if scale.is_a?(Numeric) @x*=scale @y*=scale @z*=scale elsif scale.is_a?(Position) @x*=scale.x @y*=scale.y @z*=scale.z end self end |
#+(position) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/position.rb', line 24 def +(position) @x+=position.x @y+=position.y @z+=position.z self end |
#-(position) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/position.rb', line 31 def -(position) @x-=position.x @y-=position.y @z-=position.z self end |
#eql?(position) ⇒ Boolean Also known as: ==
16 17 18 19 20 21 |
# File 'lib/position.rb', line 16 def eql?(position) self.class.equal?(position.class) && @x == position.x && @y == position.y && @z == position.z end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/position.rb', line 11 def to_s "#{@x},#{@y},#{@z}" end |