Created
August 26, 2013 19:16
-
-
Save radavis/6345422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Whiteboard | |
| attr_accessor :contents | |
| def initialize(contents = []) | |
| @contents = contents | |
| end | |
| def erase | |
| @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 any_ink_left? | |
| @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) | |
| p black_marker | |
| puts black_marker.any_ink_left? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment