On Dec 29, 5:33 pm, Robert Walker <[email protected]> wrote:
> Yep. A common mistake when iterating arrays. One solution is to build a
> new array containing the objects you want, rather than deleting objects
> that you don't want. There may be better approaches that might use less
> memory though.
And if you do want to do that, a rubyish way of doing that is to use
methods like select
The relevant portion of the code above could be written as
@tasks = @tasks.select {|task| task.root? || !
current_user.has_roles_for?(Task.find(task.parent_id))}
(probably a little faster too - Array#delete is O(n))
Fred
> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.