# Array#reject vs Array#each + in-block boolean test--I'm baffled--please help!

**URL:** <https://www.ruby-forum.com/t/array-reject-vs-array-each-in-block-boolean-test-im-baffled-please-help/144163>\
**Category:** Rails\
**Created:** [July 26, 2008, 12:17am UTC](https://www.ruby-forum.com/t/array-reject-vs-array-each-in-block-boolean-test-im-baffled-please-help/144163 "2008-07-26T00:17:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [July 26, 2008, 12:17am UTC](https://www.ruby-forum.com/t/array-reject-vs-array-each-in-block-boolean-test-im-baffled-please-help/144163/1 "2008-07-26T00:17:21Z")

</div>

Hey All,

Can someone explain the difference between these two constructs?  
Consider a Projects model, which has\_many :tasks–so tasks here is (I  
believe) an array.

Construct #1:

tasks.reject(&:new\_record?).each do |task|  
# do some stuff with task  
end

Construct #2:

tasks.each do |task|  
unless task.new\_record?  
# do some stuff with task  
end  
end

I had thought 2 was just a more verbose version of 1, but it seems  
that’s not the case. I grabbed #1 from here:  
[#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75) (the existing\_task\_attributes=  
method). I used construct #2 in my app, and found that not every task  
was getting processed.

(Specifically, if the user removed every task on the view and then  
saved, all but one would be deleted.)

Reading the one line of documentation for Array#reject, I don’t  
understand why these 2 constructs should behave differently.

Many thanks!

-Roy
