Robert Klemme
3/25/2009 5:24:00 PM
2009/3/25 Tarscher <tarscher@gmail.com>:
> I want to delete an element from an array when it matches a condition.
> But I first want to print something to the screen when a am=F9cth is
> found.
>
> I know a.delete_if but can I somehow add that print to the screen next
> to the condition? If not , is there an alternative way to delete from
> an array while iterating?
What makes you think you cannot print in the block of a delete_if?
irb(main):009:0> a =3D (1..5).to_a
=3D> [1, 2, 3, 4, 5]
irb(main):010:0> a.delete_if {|x| printf "Found %4d\n", x; x % 3 =3D=3D 0}
Found 1
Found 2
Found 3
Found 4
Found 5
=3D> [1, 2, 4, 5]
irb(main):011:0> a
=3D> [1, 2, 4, 5]
robert
--=20
remember.guy do |as, often| as.you_can - without end