Class: Position

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/position.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/position.rb', line 3

def y
  @y
end

#zObject

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: ==

Returns:

  • (Boolean)


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_sObject



11
12
13
# File 'lib/position.rb', line 11

def to_s
  "#{@x},#{@y},#{@z}"
end