Class: Point
- Inherits:
-
Object
- Object
- Point
- Defined in:
- lib/codenjoy/utils.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#==(other_object) ⇒ Object
Override of compare method for Point.
-
#down ⇒ Object
Position of point below current.
-
#initialize(x, y) ⇒ Point
constructor
Coords (1,1) - upper left side of field.
-
#left ⇒ Object
Position of point on the left side.
- #out_of?(board_size) ⇒ Boolean
-
#right ⇒ Object
Position of point on the right side.
-
#to_s ⇒ Object
For better
.inspect
output. -
#up ⇒ Object
Position of point above current.
Constructor Details
#initialize(x, y) ⇒ Point
Coords (1,1) - upper left side of field
9 10 11 12 |
# File 'lib/codenjoy/utils.rb', line 9 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
2 3 4 |
# File 'lib/codenjoy/utils.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/codenjoy/utils.rb', line 3 def y @y end |
Instance Method Details
#==(other_object) ⇒ Object
Override of compare method for Point
15 16 17 |
# File 'lib/codenjoy/utils.rb', line 15 def == (other_object) other_object.x == @x && other_object.y == @y end |
#down ⇒ Object
Position of point below current
30 31 32 |
# File 'lib/codenjoy/utils.rb', line 30 def down Point.new(@x, @y - 1) end |
#left ⇒ Object
Position of point on the left side
35 36 37 |
# File 'lib/codenjoy/utils.rb', line 35 def left Point.new(@x - 1, @y) end |
#out_of?(board_size) ⇒ Boolean
44 45 46 |
# File 'lib/codenjoy/utils.rb', line 44 def out_of?(board_size) x >= board_size || y >= board_size || x < 0 || y < 0; end |
#right ⇒ Object
Position of point on the right side
40 41 42 |
# File 'lib/codenjoy/utils.rb', line 40 def right Point.new(@x + 1, @y) end |
#to_s ⇒ Object
For better .inspect
output
20 21 22 |
# File 'lib/codenjoy/utils.rb', line 20 def to_s "[#{@x},#{@y}]" end |