Class: MapPoint::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = 0, y = 0, z = 0) ⇒ Point

Returns a new instance of Point.



5
6
7
# File 'lib/map/point.rb', line 5

def initialize(x = 0, y = 0, z = 0)
  @x, @y, @z = x, y, z
end

Instance Attribute Details

#xObject

Attributes access



10
11
12
# File 'lib/map/point.rb', line 10

def x
  @x
end

#yObject

Attributes access



10
11
12
# File 'lib/map/point.rb', line 10

def y
  @y
end

#zObject

Attributes access



10
11
12
# File 'lib/map/point.rb', line 10

def z
  @z
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Redefinition of equal operator



13
14
15
# File 'lib/map/point.rb', line 13

def ==(other)
  (self.class ==other.class) && (self.state == other.state)
end

#hashObject

It allows to use Point as a hash key



21
22
23
# File 'lib/map/point.rb', line 21

def hash
  state.hash
end

#to_sObject

To string



26
27
28
# File 'lib/map/point.rb', line 26

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