Skip to content

Instantly share code, notes, and snippets.

@choallin
Created June 18, 2019 16:07
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 choallin/60b42b3ec3c36b39b53b8cb19c2abe7a to your computer and use it in GitHub Desktop.
Save choallin/60b42b3ec3c36b39b53b8cb19c2abe7a to your computer and use it in GitHub Desktop.
class DoorLock
def initialize(locked)
@locked = locked
end
def open?
!@locked
end
def unlock!
unless open?
puts "Opening the door!"
@locked = false
end
end
end
door_lock = DoorLock.new(true)
5.times.map do
Thread.new do
unless door_lock.open?
door_lock.unlock!
end
end
end.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment