From: David Alan Black Date: 2001-04-28T12:47:36+09:00 Subject: [ruby-talk:14365] Re: RCR: Array#insert On Sat, 28 Apr 2001, TAKAHASHI Masayoshi wrote: > Hi, > > Michael Neumann wrote: > > class Array > > def insert(inx, obj) > > self[inx, 0] = obj > > self > > end > > end > > Another candidate is: > > class Array > def insert(num, elem) > if elem.kind_of? Array > self[num, 0] = [elem] > else > self[num, 0] = elem > end > self > end > end ...which I think could also be done as: class Array def insert(num, elem) self[num,0] = *[elem] self end end I haven't benchmarked them, though. (This thread is getting me thinking, in ways that I haven't formulated yet (and won't tonight :-), about the relative status of language features and just plain things written in Ruby code. Actually I have formulated some ideas along these lines in the past. But I ... well, first sleep, and then Ruby philosophizing :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav