Class: Coordinates
- Inherits:
-
Object
- Object
- Coordinates
- Includes:
- Comparable
- Defined in:
- lib/software_challenge_client/coordinates.rb
Overview
Einfache kartesische Koordinaten
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
-
.origin ⇒ Object
Gibt die Ursprungs-Koordinaten (0, 0) zurück.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(x, y) ⇒ Coordinates
constructor
Erstellt neue leere Koordinaten.
- #inspect ⇒ Object
-
#to_s ⇒ Object
Gibt eine textuelle Repräsentation der Koordinaten aus.
Constructor Details
#initialize(x, y) ⇒ Coordinates
Erstellt neue leere Koordinaten.
9 10 11 12 |
# File 'lib/software_challenge_client/coordinates.rb', line 9 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
6 7 8 |
# File 'lib/software_challenge_client/coordinates.rb', line 6 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
6 7 8 |
# File 'lib/software_challenge_client/coordinates.rb', line 6 def y @y end |
Class Method Details
.origin ⇒ Object
Gibt die Ursprungs-Koordinaten (0, 0) zurück.
19 20 21 |
# File 'lib/software_challenge_client/coordinates.rb', line 19 def self.origin Coordinates.new(0, 0) end |
Instance Method Details
#+(other) ⇒ Object
33 34 35 |
# File 'lib/software_challenge_client/coordinates.rb', line 33 def +(other) Coordinates.new(x + other.x, y + other.y) end |
#<=>(other) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/software_challenge_client/coordinates.rb', line 23 def <=>(other) xComp = x <=> other.x yComp = y <=> other.y if xComp == 0 yComp else xComp end end |
#==(other) ⇒ Object
14 15 16 |
# File 'lib/software_challenge_client/coordinates.rb', line 14 def ==(other) x == other.x && y == other.y end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/software_challenge_client/coordinates.rb', line 42 def inspect to_s end |
#to_s ⇒ Object
Gibt eine textuelle Repräsentation der Koordinaten aus.
38 39 40 |
# File 'lib/software_challenge_client/coordinates.rb', line 38 def to_s "(#{x}, #{y})" end |