Bugs item #3175, was opened at 2006-01-03 19:49
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=3175&group_id=426

Category: Core
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Phil Duby (pduby)
Assigned to: Nobody (None)
Summary: enum.find with ifnone calls ifnone process even if find succeeds

Initial Comment:
This is using ruby 1.8.2 (2004-12-25) [i386-mswin32] on windows XP pro

Calling the find method on an Array including the optional (ifnone) block parameter cause the ifnone block to always be executed, even if the find
succeeds.  In fact, from my testing, it is called before the first call to the regular find block.  The documenation (rdoc) says the ifnone block should only be called if the find block does not match any object.

From the inheritance, I assume the problem in in enum, not in the Array class.

Below is the output from the small ruby program I attached to demonstrate the error.  The 999 and following array values are dummy entries I had the ifnone and find blocks add, to verify the sequence of calls.

> ruby -v -w bug_find_with_ifnone.rb
ruby 1.8.2 (2004-12-25) [i386-mswin32]
Initial powers array = [2]
start more_powers( 15, 2)
end more_powers( 15, 999) = 16
Adjusted powers array = [2, 4, 8, 16, 999]
Found next power after 15 = 16
Using find without an ifnone clause
Found next power after 7 = 8
Unchanged powers array = [2, 4, 8, 16, 999]
Same find that does not reach the end of the array, but with
an ifnone clause that will update the array if called
start more_powers( 28, 999)
end more_powers( 28, 999) = 999
Changed powers array = [2, 4, 8, 16, 999, 999, 2, 4, 8]
Found next power after 7 = 8


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=3175&group_id=426