From: murphy Date: 2007-11-15T08:10:42+09:00 Subject: Re: Proposal: Array#walker Hugh Sasse wrote: >> Actually, can anyone recommend a better name than #crack? --or a way >> to already do this? > > ...split (taken)... no, it's not. however, String.split works in a different way, so maybe this isn't the best name. Array#split_at seems a logical option. I would expect it to behave like an anti-slice: /* * call-seq: * array.split_at(index) -> [left_array, right_array] * array.split_at(start, length) -> [left_array, right_array] * array.split_at(range) -> [left_array, right_array] * * Splits an array into two parts, with the first one containing * all elements before the given range, and the second one containing * all elements after it. See Array#slice for information about the * range expressions. * * a = [ "a", "b", "c", "d", "e" ] * a.split_at(0) #=> [[], ["b", "c", "d", "e"]] * a.split_at(2) #=> [["a", "b"], ["d", "e"]] * a.split_at(-1) #=> [["a", "b", "c", "d"], []] * a.split_at(1, 2) #=> [["a"], ["d", "e"]] * a.split_at(1, 0) #=> [["a"], ["b", "c", "d", "e"]] * a.split_at(1..3) #=> [["a"], ["e"]] * a.split_at(0..-1) #=> [[], []] * * range = 1..3 * slice = a.slice(range) * pre, post = a.split_at(range) * a == pre + slice + post #=> true * */ [murphy]