From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-30T09:45:54+09:00 Subject: Re: Array.extend versus instance.extend On Fri, 30 May 2003 01:15:32 +0900, Guillaume Marcais wrote: > module ArrayMisc2 > def shift_until(klass) > p = -1 > detect { |x| p += 1; klass === x } > slice!(0, p) > end > def pop_until(klass) > p = -1 > reverse.detect { |x| p += 1; klass === x } > slice!(-p, p) > end > end Sorry your code does not pass all the tests.. it has somekind of different behavier. I have never tried using 'Enumable#detect' before so I cannot figure out exactly what seems to be the problem. Thanks for trying :-) > ruby test_misc.rb TestMisc#test_pop_until . TestMisc#test_pop_until_non_existing_class F. TestMisc#test_pop_until_regex . TestMisc#test_shift_until . TestMisc#test_shift_until_non_existing_class F. TestMisc#test_shift_until_regex . Time: 0.015673 FAILURES!!! Test Results: Run: 6/6(10 asserts) Failures: 2 Errors: 0 Failures: 2 test_misc.rb:37:in `test_pop_until_non_existing_class'(TestMisc): expected:<[]> but was:<[1]> (RUNIT::AssertionFailedError) from test_misc.rb:49 test_misc.rb:19:in `test_shift_until_non_existing_class'(TestMisc): expected:<[]> but was:<[6]> (RUNIT::AssertionFailedError) from test_misc.rb:49 > The test cases looks like this: def test_shift_until_non_existing_class ary = [1, 2, "a", 3, 4, "b", 5, 6] res = ary.shift_until(IO) assert_equal([], ary) # BOOM assert_equal([1, 2, "a", 3, 4, "b", 5, 6], res) end def test_pop_until_non_existing_class ary = [1, 2, "a", 3, 4, "b", 5, 6] res = ary.pop_until(IO) assert_equal([], ary) # BOOM assert_equal([1, 2, "a", 3, 4, "b", 5, 6], res) end -- Simon Strandgaard