From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-30T17:26:48+09:00 Subject: Re: Array.extend versus instance.extend On Fri, 30 May 2003 11:41:21 +0900, dblac wrote: > > Here's a modification of Guillaume's code that passes your tests: I ran the test-suite on your code and it failed. I have adapted+adjusted the code so it now works properly :-) module ArrayMisc def shift_until(klass) p = 0 detect do |x| if klass === x true else p += 1 false end end slice!(0, p) end def pop_until(klass) p = 0 reverse.detect do |x| if klass === x true else p += 1 false end end slice!(-p, p) end end > ruby test_misc.rb TestMisc#test_pop_until . TestMisc#test_pop_until_non_existing_class . TestMisc#test_pop_until_regex . TestMisc#test_shift_until . TestMisc#test_shift_until_non_existing_class . TestMisc#test_shift_until_regex . Time: 0.011196 OK (6/6 tests 12 asserts) > My earlier code says 'Time: 0.007166'.. so this is a *slower* solution. -- Simon Strandgaard