Class: Ship
Overview
class Ship describes ship state
Constant Summary
Constants included from State
State::BROKEN, State::EMPTY, State::MISSED, State::SHIP
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #include?(cell) ⇒ Boolean
-
#initialize(cells) ⇒ Ship
constructor
A new instance of Ship.
Constructor Details
#initialize(cells) ⇒ Ship
Returns a new instance of Ship.
14 15 16 17 |
# File 'lib/ship.rb', line 14 def initialize(cells) @cells = cells @cells.each { |c| c.state = SHIP } end |
Instance Method Details
#alive? ⇒ Boolean
19 20 21 22 |
# File 'lib/ship.rb', line 19 def alive? @cells.each { |c| return true if c.state == SHIP } false end |
#include?(cell) ⇒ Boolean
24 25 26 |
# File 'lib/ship.rb', line 24 def include?(cell) @cells.include? cell end |