Class: TicTacToe::Cursor
- Inherits:
-
Object
- Object
- TicTacToe::Cursor
- Defined in:
- lib/tic_tac_toe/cursor.rb
Constant Summary collapse
- OutOfBounds =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
-
#initialize(field = nil, board) ⇒ Cursor
constructor
A new instance of Cursor.
- #move(direction) ⇒ Object
Constructor Details
#initialize(field = nil, board) ⇒ Cursor
Returns a new instance of Cursor.
7 8 9 10 11 12 |
# File 'lib/tic_tac_toe/cursor.rb', line 7 def initialize(field = nil, board) @field = field || board.fields.first @board = board raise OutOfBounds unless @board.fields.include?(@field) end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/tic_tac_toe/cursor.rb', line 5 def field @field end |
Instance Method Details
#move(direction) ⇒ Object
14 15 16 17 18 |
# File 'lib/tic_tac_toe/cursor.rb', line 14 def move(direction) send(direction) rescue TicTacToe::Cursor::OutOfBounds self end |