#!/usr/bin/env ruby # Can run on any computer with ruby installed, with "ruby run_names.rb" 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)] # could use hat.sample instead, the sample method randomly picks from an array. puts "#{participant.name} picks #{pick.name}" unless pick == participant participant.buys_for = pick hat.delete(pick) end end end