Class: Doku::SquareOnGrid

Inherits:
Struct
  • Object
show all
Defined in:
lib/doku/grid.rb

Overview

Represents a square on a grid. Any two instances with the same x and y coordinates are considered to be equal, which makes it convenient to use SquareOnGrid instances as a key in a hash table. This class is used by the PuzzleOnGrid module to represent the squares in grid-based Puzzles.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



229
230
231
# File 'lib/doku/grid.rb', line 229

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



229
230
231
# File 'lib/doku/grid.rb', line 229

def y
  @y
end

Instance Method Details

#matches?(conditions) ⇒ Boolean

Returns True if the square matches all the conditions.

Parameters:

  • conditions (Hash)

    Should be a hash where the keys are :x or :y and the values are either Integers or Integer ranges.

Returns:

  • (Boolean)

    True if the square matches all the conditions.



233
234
235
# File 'lib/doku/grid.rb', line 233

def matches?(conditions)
  conditions.all? { |property, values| values === send(property) }
end

#to_sObject



237
238
239
# File 'lib/doku/grid.rb', line 237

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