ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: delete_if_with_index or delete_at(array) in 1.8.6?
by Robert Klemme other posts by this author
Jul 2 2009 7:38AM 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?
2009/7/2 James Gray <james@[...].net> :

>  You need to reread what Bil was asking for.  ;)

Right.  Now I got it.  He means something like

irb(main):001:0>  a = (1..10).map { rand(10) }
=>  [8, 0, 4, 2, 1, 4, 5, 4, 2, 9]
irb(main):002:0>  i = -1
=>  -1
irb(main):003:0>  a.delete_if {|x| i += 1; x < i}
=>  [8, 4, 9]
irb(main):004:0> 

Correct?  Thanks for the heads up, James!

Site note: there seems to be a certain setting of the mind which
prevents that we consider a mutating operation in a "read only" block
used as filtering criterion.  Yet we can do it.  It took me a while,
too. :-)

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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved