shared/run_names.rb

41 lines
939 B
Ruby

#!/usr/bin/env ruby
adults = [ 'Allen', 'Vickie', 'Matt', 'Lisa', 'James', 'Pich', 'Kristen', 'Jason', 'Markie' ]
kids = [ 'Malachi', 'Isaiah', 'Samara', 'Ethan', 'Kennedi', 'Kasen', 'Griffin', 'Millie', 'Otto' ]
names = adults
class Participant
attr_accessor :name
attr_accessor :buys_for
def initialize name
@name = name
end
end
participants = Array.new
names.each { |name| participants.push Participant.new(name) }
# put everyone's name in the hat
hat = Array.new
participants.each { |participant| hat.push participant }
# randomize the order names are picked
pick_order = participants.shuffle
# pick names from hat, making sure they don't pick themself
pick_order.each do |participant|
while participant.buys_for == nil
pick = hat[rand(hat.length)]
puts "#{participant.name} picks #{pick.name}"
unless pick == participant
participant.buys_for = pick
hat.delete(pick)
end
end
end