Forum: Ruby Re: Delete line from file

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
825738339f48c5b8b2a72c02caf3d91c?d=identicon&s=25 Gavin Kistner (Guest)
on 2007-01-03 00:48
(Received via mailing list)
> => ["a", "b", "c", "d", "e", "f"]
> irb(main):005:0> [1,3,5].each {|e| a.slice!(e) }
> => [1, 3, 5]
> irb(main):006:0> a
> => ["a", "c", "d", "f"]
> You'd probably want to reverse the list of indices.

Or perhaps:
  irb(main):001:0> a = %w{a b c d e f }
  => ["a", "b", "c", "d", "e", "f"]
  irb(main):002:0> [1,3,5].each{ |e| a[e] = nil }
  => [1, 3, 5]
  irb(main):003:0> a.compact
  => ["a", "c", "e"]

Remembering, of course, that the 1st line is the 0th line number.
This topic is locked and can not be replied to.