Class: Robot::Point
- Inherits:
-
Object
- Object
- Robot::Point
- Defined in:
- lib/robot/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #east ⇒ Object
-
#initialize(x:, y:) ⇒ Point
constructor
A new instance of Point.
- #north ⇒ Object
- #south ⇒ Object
- #to_s ⇒ Object
- #west ⇒ Object
Constructor Details
#initialize(x:, y:) ⇒ Point
Returns a new instance of Point.
9 10 11 12 |
# File 'lib/robot/point.rb', line 9 def initialize(x:, y:) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/robot/point.rb', line 7 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/robot/point.rb', line 7 def y @y end |
Instance Method Details
#<(other) ⇒ Object
38 39 40 |
# File 'lib/robot/point.rb', line 38 def <(other) x < other.x || y < other.y end |
#==(other) ⇒ Object
30 31 32 |
# File 'lib/robot/point.rb', line 30 def ==(other) x == other.x && y == other.y end |
#>(other) ⇒ Object
34 35 36 |
# File 'lib/robot/point.rb', line 34 def >(other) x > other.x || y > other.y end |
#north ⇒ Object
14 15 16 |
# File 'lib/robot/point.rb', line 14 def north Point.new(x: x, y: y + 1) end |
#south ⇒ Object
18 19 20 |
# File 'lib/robot/point.rb', line 18 def south Point.new(x: x, y: y - 1) end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/robot/point.rb', line 42 def to_s "#{x}, #{y}" end |