On Jan 1, 2:18=A0pm, pharrington <xenogene... / gmail.com> wrote:
> On Jan 1, 11:45=A0am, Joe Buck <semle2... / hotmail.com> wrote:
>
>
>
>
>
> > Ehsan,
>
> > Thanks for the help. Unfortunately I don't think that will work as it
> > removes the first element in the array.
>
> > What I need is an Array::delete_if or Array::reject! call that allows m=
e
> > to break from the block while still removing elements.
>
> > My solution is to use a second array to keep the indices of all removed
> > elements. I can then iterate through the second array after the first
> > loop and remove the elements. I'm guessing reject! and delete_if do thi=
s
> > as well. It could be more efficient but it works.
>
> > Thanks!
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> Without knowing the point of what you're trying to do, this sounds
> like what you have in mind:
>
> array =3D [] # or whatev
> process_array =3D true
> array.reject!(x) do
> =A0 if process_array
> =A0 =A0 conditional_code_for x
> =A0 else
> =A0 =A0 false
> end

Also, is the reject! really the bottleneck in your app? We obviously
don't want to intentionally write sub-optimal code, but do not
optimize what's not slowing you down.