From: dblack@... Date: 2003-05-30T18:48:55+09:00 Subject: Re: Array.extend versus instance.extend Hi -- On Fri, 30 May 2003, Simon Strandgaard wrote: > 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. Try again :-) It shouldn't fail. Here's what I ran, cut-and-pasted from your message and my message, plus the TestUnit wrapper: module ArrayMisc2A def shift_until(klass) p = 0 detect { |x| p += 1 and klass === x } slice!(0, p) end def pop_until(klass) p = 0 reverse.detect { |x| p += 1 and klass === x } slice!(-p, p) end end class Array; include ArrayMisc2A; end require 'test/unit' class TestMe < Test::Unit::TestCase 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 end Output: $ ruby shifttwo.rb Loaded suite shifttwo Started... ... Finished in 0.002075 seconds. 2 runs, 4 assertions, 0 failures, 0 errors David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav