Created
November 12, 2018 00:57
-
-
Save jnarowski/ba5d16ed4bdb4146c7ffadcc27ff199e 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 SecretSantaPicker | |
def pick! | |
matches = {} | |
people = [ | |
'JP', | |
'Wladyslaw', | |
'Nell', | |
'JP', | |
'Pam', | |
'Marianna', | |
'Scott', | |
'Joe', | |
'Natasha', | |
'Franz', | |
'Helena' | |
] | |
people.each do |person| | |
matches[person] = select_secret_santa(person, people, matches) | |
end | |
matches | |
end | |
private | |
def select_secret_santa(person, people, matches) | |
selected_people = matches.values | |
remaining_peeps = people - selected_people | |
secret_santa = remaining_peeps.shuffle.first | |
if secret_santa == person | |
raise StandardError, "[ERROR] retrying. can't pick yourself" | |
end | |
secret_santa | |
rescue | |
p "[ERROR] retrying. can't pick yourself" | |
retry | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment