From: matz@... (Yukihiro Matsumoto) Date: 2002-01-28T14:25:30+09:00 Subject: Re: Array#splice method Hi, In message "Array#splice method" on 02/01/28, michael libby writes: |So being fairly new at Ruby (and not even sure this works 100% like the |Perl splice), I'd love comments and suggestions-- especially since I've |only got a few unit tests (mostly the aforementioned sandwich example). |Anything I missed that will break easily? Anything that could be written |better another way? Any Ruby idioms I've totally flubbed? Most of them can be accomplished by other methods; that's why I didn't prepare splice, which behavior is sort of hard for me to use. # make a basic sandwich sandwich = %w( bread bologna bread ) p sandwich # change our mind, go for club sandwich instead. sandwich.[1,1] = %w( chicken lettuce bread bacon mayo ) p sandwich # hmmm. hold the mayo and butter the bread, please sandwich[1,0] = ['butter'] p sandwich sandwich[-2,1] = ['butter'] p sandwich # time for lunch mouth = sandwich.slice!(0..-1) p mouth p sandwich # try to cause indigestion # we can't do this directly; but I'm not sure how this is important #gullet = mouth.splice( -99999, 256, ['vinegar', 'baking soda']) #puts mouth.inspect # we can't do this directly; but I'm not sure how this is important #gullet = mouth.splice( 256, -9, ['zotz'] ) #puts mouth.inspect mouth[1,256] = ['pickles', 'ice cream'] p mouth matz.