Class: Karel::FreeSquare
Overview
A square that can hold a beeper, or Karel.
Instance Method Summary collapse
- #beeper? ⇒ Boolean
-
#initialize(beeper = false) ⇒ FreeSquare
constructor
A new instance of FreeSquare.
- #pick_beeper ⇒ Object
- #put_beeper ⇒ Object
- #to_s ⇒ Object
- #wall? ⇒ Boolean
Constructor Details
#initialize(beeper = false) ⇒ FreeSquare
Returns a new instance of FreeSquare.
7 8 9 |
# File 'lib/karel/square.rb', line 7 def initialize(beeper=false) @beeper = beeper end |
Instance Method Details
#beeper? ⇒ Boolean
13 |
# File 'lib/karel/square.rb', line 13 def beeper?; @beeper; end |
#pick_beeper ⇒ Object
15 16 17 18 |
# File 'lib/karel/square.rb', line 15 def pick_beeper raise NoBeeper unless beeper? @beeper = false end |
#put_beeper ⇒ Object
20 21 22 23 |
# File 'lib/karel/square.rb', line 20 def put_beeper raise SquareOccupied if beeper? @beeper = true end |
#to_s ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/karel/square.rb', line 25 def to_s if beeper? "B" else " " end end |
#wall? ⇒ Boolean
11 |
# File 'lib/karel/square.rb', line 11 def wall?; false; end |