From: Michel Demazure Date: 2010-10-11T20:42:19+09:00 Subject: Re: Testing for subarrays David A. Black wrote: > Here's another way that is more verbose but that doesn't create the > whole array (which probably doesn't matter anyway, unless it's a huge > array and you're cycle-shaving). I also prefer extending individual > objects, rather than adding to Array. > > module SubArrayFinder > def look_up(sub_array) > sub_size = sub_array.size > index = find_index.with_index do |e,i| > self[i, sub_size] == sub_array > end > return(index..index+sub_size-1) if index > end > end Comparing with my original proposal, a side question is whether using each_cons is faster, or not, that iterating with self[i, sub_size]... _md -- Posted via http://www.ruby-forum.com/.