From: Yossef Mendelssohn Date: 2008-07-08T09:24:13+09:00 Subject: Re: Find matching elements in array On Jul 7, 1:32 am, Sandor Szücs wrote: > class Array > alias old_include? include? > def include?(*args) > > if args.length <= 1 > old_include?(args) > else > args.all? do |a| > old_include?(a) > end > end > end > end > > puts("#{(0..9).to_a.include?(3,5)}") # true > puts("#{('a'..'z').to_a.include?(3,5)}") # false > puts("#{('A'..'ZZ').to_a.include?('G','AB')}")# true > > regards, Sandor Szücs > -- Two things: 1) This doesn't work. Try ('a'..'z').to_a.include?('a') 2) The length check isn't necessary. It's sufficient to just use args.all? { |a| old_include?(a) }, assuming it's okay that calling include? with no arguments now returns true. I like Mikel's set-intersection solution (which, incidentally, is what I was thinking), assuming once again that the order is important. -- -yossef