Skip to content

Instantly share code, notes, and snippets.

@reitzig
Last active December 5, 2018 10:11
Show Gist options
  • Save reitzig/3a2c97274a6ed09bf049092b0d67e76d to your computer and use it in GitHub Desktop.
Save reitzig/3a2c97274a6ed09bf049092b0d67e76d to your computer and use it in GitHub Desktop.
Invite people to a Secret Santa without you knowing who draws whom (sketch)
#!/usr/bin/env ruby
participants = [
{ :name => "Santa", :email => "santa@north.mas" },
{ :name => "Rudolf", :email => "rednose@north.mas" },
{ :name => "Ruprecht", :email => "knecht77@north.mas" }
]
def assign_gifts(folks)
perm = (0...folks.size).to_a.shuffle
perm.zip(perm.rotate(1)).each { |pair|
send_mail(folks[pair[0]][:email], folks[pair[1]][:name])
}
end
def send_mail(to, gift_to)
puts "Tell #{to} to prepare a 🔒-🎅 🎁 for #{gift_to}"
# Real implementation e.g. with: https://jerodsanto.net/2009/02/a-simple-ruby-method-to-send-emai/
end
assign_gifts(participants)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment