class Sudoku::CellCoordinates
Represents a two dimensional coordinates in the Sudoku
grid.
Attributes
coordinate_x[R]
coordinate_y[R]
Public Class Methods
new(x, y)
click to toggle source
Will initialize this cell coordinate.
-
x
horizontal coordinate. -
y
vertical coordinate.
# File lib/sudoku/model/cell_coordinates.rb, line 12 def initialize(x, y) @coordinate_x = Sudoku::Coordinate.new(x) @coordinate_y = Sudoku::Coordinate.new(y) end
random()
click to toggle source
Will return randomly generated coordinate.
# File lib/sudoku/model/cell_coordinates.rb, line 50 def self.random CellCoordinates.new(Random.rand(0..8), Random.rand(0..8)) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/sudoku/model/cell_coordinates.rb, line 29 def <=>(other) return @coordinate_y <=> other.coordinate_y if @coordinate_y != other.coordinate_y @coordinate_x <=> other.coordinate_x end
==(other)
click to toggle source
# File lib/sudoku/model/cell_coordinates.rb, line 17 def ==(other) self.class == other.class && @coordinate_x == other.coordinate_x && @coordinate_y == other.coordinate_y end
Also aliased as: eql?
hash()
click to toggle source
# File lib/sudoku/model/cell_coordinates.rb, line 25 def hash @coordinate_x.coordinate ^ @coordinate_y.coordinate # XOR, from the doc end
in_area(x, y)
click to toggle source
Will return true, if this coordinate belongs to area given by two ranges of coordinates.
-
x
range of x coordinates to accept. -
y
range of y coordinates to accept.
# File lib/sudoku/model/cell_coordinates.rb, line 44 def in_area(x, y) return true if x.include?(@coordinate_x) && y.include?(@coordinate_y) false end
to_s()
click to toggle source
Will return this coordinate in the format [x, y]
# File lib/sudoku/model/cell_coordinates.rb, line 36 def to_s "[#{coordinate_x}, #{coordinate_y}]" end