Created
June 18, 2019 16:07
-
-
Save choallin/60b42b3ec3c36b39b53b8cb19c2abe7a to your computer and use it in GitHub Desktop.
This file contains 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 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