Skip to content

Instantly share code, notes, and snippets.

@Yardboy
Created August 27, 2014 18:51
Show Gist options
  • Save Yardboy/05bb7f5044d7db2bbf5a to your computer and use it in GitHub Desktop.
Save Yardboy/05bb7f5044d7db2bbf5a to your computer and use it in GitHub Desktop.
Ruby any? and all? with an empty array as receiver.
2.0.0-p451 :001 > [].any? { |wtf| wtf.locked? }
=> false
2.0.0-p451 :002 > [].all? { |wtf| wtf.locked? }
=> true
@bkerley
Copy link

bkerley commented Aug 27, 2014

Enumerable#any? "Does at least one element of the collection fulfill the condition?"

Enumerable#all? "Do all the elements of the array fulfill the condition?"

With an empty collection, zero elements fulfill the condition. Which isn't at least one, but is all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment