Class: SnakesAndLadders::Cell
- Inherits:
-
Object
- Object
- SnakesAndLadders::Cell
- Defined in:
- lib/snakes_and_ladders/cell.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
- #enter(player, board) ⇒ Object
- #exit(player) ⇒ Object
-
#initialize(location:, players: []) ⇒ Cell
constructor
A new instance of Cell.
Constructor Details
#initialize(location:, players: []) ⇒ Cell
Returns a new instance of Cell.
5 6 7 8 |
# File 'lib/snakes_and_ladders/cell.rb', line 5 def initialize(location:, players: []) @location = location @players = players end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
3 4 5 |
# File 'lib/snakes_and_ladders/cell.rb', line 3 def location @location end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
3 4 5 |
# File 'lib/snakes_and_ladders/cell.rb', line 3 def players @players end |
Instance Method Details
#enter(player, board) ⇒ Object
14 15 16 17 |
# File 'lib/snakes_and_ladders/cell.rb', line 14 def enter(player, board) players.push(player) && player.position = location puts "#{player} is on square #{location}." end |
#exit(player) ⇒ Object
10 11 12 |
# File 'lib/snakes_and_ladders/cell.rb', line 10 def exit(player) players.delete(player) end |