Pete Elmore wrote:
> Ben wrote:
> > a = [1,2,3,4,5]
> > b = [1,4]
> >
> > a.include?(b) will only work if b is a string. I'd like to get a
> > true/false if b exists in a.
> The to_set solution is probably better, but you could do something like
> class Array
> 	def subset(s)
> 		!s.find { |el| !self.include? el }
> 	end
> end
>
> irb(main):018:0> [1, 2, 3, 4].subset([1, 2])
> => true
> irb(main):019:0> [1, 2, 3, 4].subset([1, :seventy_five])
> => false

I benchmarked, and to_set came out way slower:

to_set.subset? another.to_set
  0m19.089s

!another.find {|member| !include?(member)}
  0m2.628s

another.all? {|member| include? member} # my solution
  0m2.493s