From: Lars Haugseth Date: 2012-04-11T20:16:33+09:00 Subject: Re: less absolutely horrible way to make sure array 1 only contains elements from array 2? On 04/11/2012 03:44 AM, ruby ismyname wrote: > I need to make sure that myselections only contains elements from > choices, includes? doesn't work because it allows for partial matches. > This works but it looks absolutely horrible. > require 'set' valid_choices = Set[:a, :b, :c, :d, :e, :f] good = Set[:a, :b, :d, :e] good.subset? choices => true bad = Set[:c, :f, :x, :y] bad.subset? choices => false Note: you can use Array#to_set to convert an array to a set. -- Lars Haugseth