Class: Karel::FreeSquare

Inherits:
Square
  • Object
show all
Defined in:
lib/karel/square.rb

Overview

A square that can hold a beeper, or Karel.

Instance Method Summary collapse

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

Returns:

  • (Boolean)


13
# File 'lib/karel/square.rb', line 13

def beeper?; @beeper; end

#pick_beeperObject

Raises:



15
16
17
18
# File 'lib/karel/square.rb', line 15

def pick_beeper
  raise NoBeeper unless beeper?
  @beeper = false
end

#put_beeperObject

Raises:



20
21
22
23
# File 'lib/karel/square.rb', line 20

def put_beeper
  raise SquareOccupied if beeper?
  @beeper = true
end

#to_sObject



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

Returns:

  • (Boolean)


11
# File 'lib/karel/square.rb', line 11

def wall?; false; end