From: Robert Klemme Date: 2007-11-08T16:15:05+09:00 Subject: Re: how to delete array On 07.11.2007 21:02, Surjit Nameirakpam wrote: > Problem > > consider an array > > a = [1,4,6,7,9,8] > > I want to delete the array value w.r.t index > > e.g i want to delte 0,4,6 element in one go > > I can use the command > a.delete_at(0) > a.delete_at(4) > a.delete_at(6) > > But the problem is that i dont know how much element will be populated > in my array every time the program runs and the index value will also > change. > > So i need to dynamically pass the index value and this should delete the > values pertaining to the index I am surprised nobody mentioned slice - just apply indexes in decreasing order: irb(main):012:0> a = [1,4,6,7,9,8] => [1, 4, 6, 7, 9, 8] irb(main):013:0> a.slice! 2,1 => [6] irb(main):014:0> a => [1, 4, 7, 9, 8] irb(main):015:0> a.slice! 1,1 => [4] irb(main):016:0> a => [1, 7, 9, 8] Kind regards robert