Bobochka
12/28/2016 - 8:26 PM

Secret Santa

Secret Santa

names = [:a, :b, :c, :d, :e]

def pair(names)
  names
    .map 
    .with_index { |e, i| [e, i] }
    .shuffle
    .tap { |shuffled| shuffled.push(shuffled.first) }
    .each_cons(2)
    .map { |a, b| [a.first, b.first] }
    .to_h
end

pair names
# => {:a=>:e, :e=>:b, :b=>:d, :d=>:c, :c=>:a}