I often wanted to be able to simply remove some objects from an array  
without creating another array (using Array#without for instance).
Array#splice seems to be the only way to change an array in place, and  
using it is not really easy nor readable.

I submitted a patch (http://dev.rubyonrails.org/ticket/11042) which  
defines two methods I find useful:
  - Array#removeAt(index), which removes an object given its index
  - Array#removeIf(iterator[, context]), which removes objects for  
which iterator returns a truthy value

These two methods are directly inspired from they Ruby equivalent  
Array#delete_at and Array#delete_if, with "delete" renamed "remove" as  
"delete" is a Javascript keyword, and in anticipation of a future  
Ruby's Array#delete_if returns instance (this) but this implementation  
returns an array of removed objects, which I think is less suprising  
(please give your opinionon this point).

There are also corresponding unit tests which passes on all supported  
platforms (adapted from Ruby trunk ones), and inline documentation in  
PDoc format.

I hope this will be helpful for everyone !

Samuel Lebeau

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to