Skip to content

Instantly share code, notes, and snippets.

@adeng21
Created March 3, 2014 19:33
Show Gist options
  • Save adeng21/9332870 to your computer and use it in GitHub Desktop.
Save adeng21/9332870 to your computer and use it in GitHub Desktop.
Whiteboard & DryEraseMarker Instance Method Examples
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase(contents)
@contents.delete(contents.length)
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 capacity_empty?
if @capacity =< 0
true
else
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment