From: "Sandor Szücs" Date: 2008-07-08T18:16:14+09:00 Subject: Re: Find matching elements in array Hi, On 08.07.2008, at 02:24, Yossef Mendelssohn wrote: > 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') ack. > 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. ack. > I like Mikel's set-intersection solution (which, incidentally, is what > I was thinking), assuming once again that the order is important. That's also what I thought if I read that e-mail. regards, Sandor Szücs --