Re: delete_if_with_index or delete_at(array) in 1.8.6?
by Robert Klemme other posts by this author
Jul 2 2009 1:50PM messages near this date
Re: delete_if_with_index or delete_at(array) in 1.8.6?
|
Re: delete_if_with_index or delete_at(array) in 1.8.6?
On 02.07.2009 20:33, Bil Kleb wrote:
> Robert Klemme wrote:
> > irb(main):002:0> i = -1
> > irb(main):003:0> a.delete_if {|x| i += 1; x < i}
>
> Ah, if it weren't for the two lines, I think I'd pick
> this one.
Even with two lines I personally find it more elegant than some of the
solutions you posted. I can even give you reasons:
- it is straightforward and thus easy to understand
- little code, despite the two lines
- it does not create any temporary arrays of indexes or such which is
the reason for:
- it is probably pretty efficient
- oh, and it should work on all versions of Ruby
:-)
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Thread:
Bil Kleb
David A. Black
Bil Kleb
James Gray
Robert Klemme
James Gray
Robert Klemme
Bil Kleb
Robert Klemme
Bil Kleb
|