Skip to content

Instantly share code, notes, and snippets.

@Murphydbuffalo
Created June 1, 2014 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Murphydbuffalo/e2fe01e312f894d243d2 to your computer and use it in GitHub Desktop.
Save Murphydbuffalo/e2fe01e312f894d243d2 to your computer and use it in GitHub Desktop.
Solution to the whiteboard mini-challenge (OOD reading)
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase_whiteboard
@contents = []
end
end
class DryEraseMarker
attr_reader :color, :capacity
def initialize(color)
@color = color
@capacity = 100
end
INK_USE_PER_CHARACTER = 0.01
def write(contents, whiteboard)
@capacity = @capacity - (INK_USE_PER_CHARACTER * contents.length)
whiteboard.contents << contents
end
def has_ink?
@capacity != 0
end
end
whiteboard = Whiteboard.new
black_marker = DryEraseMarker.new('black')
black_marker.write('Hello Launchers', whiteboard)
black_marker.write('My name is Slim Shady', whiteboard)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment