Project

General

Profile

Actions

Bug #6760

closed

unexpected behavior in Enumerable method all? if collection is empty

Added by shemerey (Anton Shemerey) over 12 years ago. Updated over 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Backport:
[ruby-core:46566]

Description

if collection is empty all? always return true even if we call it with undefined method

for example

-> [].all?(&:undefined_mathod) #=> true
-> {}.all?(&:undefined_mathod) #=> true

etc.

my fix for it un ruby:

module Enumerable
alias_method :_original_method_all?, :all?

def all?(&block)
return false if count == 0

if block_given?
  _original_method_all?(&block)
else
  _original_method_all?
end

end
end

example test file in attach


Files

test_for_enumerable_all.rb (3.21 KB) test_for_enumerable_all.rb shemerey (Anton Shemerey), 07/21/2012 01:11 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0