Inject a two-dimensional array to set
require 'set'
games = [["Alice", "Bob"], ["Carol", "Ted"],
["Alice", "Mallory"], ["Ted", "Bob"]]
p players = games.inject(Set.new) { |set, game| game.each { |p| set << p }; set }
# => #<Set: {"Alice", "Mallory", "Ted", "Carol", "Bob"}>
p players << "Ted"
# => #<Set: {"Alice", "Mallory", "Ted", "Carol", "Bob"}>
Related examples in the same category