From: David Alan Black Date: 2002-02-24T12:34:09+09:00 Subject: Re: arr.delete bug? Hello -- On Sun, 24 Feb 2002, Kinfe wrote: > Hi, > > I am using cygwin version of Ruby (belive it 1.65) > arr.delete(arr.first) will delete duplicated record in the array. Does > it do a 'sort|uniq -d' stuff internally? > > DATA. > > name address phone > > joe ny 123e23 > doe ny 123e23 > joe ny 123e23 > doe nj 11321 > > while !(arr.empty?) > a = arr.first.split > puts a > arr.delete(arr.first) > end > > The second 'joe ny 123e23' never got printed, it just disappear. Is > this a bug or what? "Or what" :-) Here's the ri documentation for Array#delete: ----------------------------------------------------------- Array#delete arr.delete( anObject ) -> anObject or nil arr.delete( anObject ) {| | block } -> anObject or nil ------------------------------------------------------------------------ Deletes items from the self that are equal to anObject. If the item is not found, returns nil. If the optional code block is given, returns the result of block if the item is not found. a = [ "a", "b", "b", "b", "c" ] a.delete("b") #=> "b" a #=> ["a", "c"] a.delete("z") #=> nil a.delete("z") { "not found" } #=> "not found" David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav