# Enumerable#all? and empty arrays

**URL:** <https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518>\
**Category:** Ruby\
**Created:** [August 9, 2006, 6:44pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518 "2006-08-09T18:44:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 6:44pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/1 "2006-08-09T18:44:09Z")

</div>

Hello

I found this to be somewhat amusing:

> > a = []  
> > =\> []
> 
> > a.all?  
> > =\> true
> 
> > a.all? { |i| i == 10 }  
> > =\> true

Is there any reasoning for Enumerable#all? to always return true for  
empty arrays?

Best regards,  
Andre

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/2 "2006-08-09T19:35:14Z")

</div>

On Thu, 10 Aug 2006, Andre N. wrote:

> Is there any reasoning for Enumerable#all? to always return true for  
> empty arrays?
> 
> Best regards,  
> Andre

well - it’s either that or false. we’d need maybe for it to really make  
sense.

consider

[].all?{|x| x.nil?} # true or false??

either is arbitrary

-a

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/3 "2006-08-09T19:50:15Z")

</div>

Andre N. wrote:

> =\> true
> 
> > > a.all? { |i| i == 10 }
> 
> =\> true
> 
> Is there any reasoning for Enumerable#all? to always return true for  
> empty arrays?

It’s what modern logic says… or something like it.

> **[Square of opposition](https://en.wikipedia.org/wiki/Square_of_opposition#The_problems_of_existential_import)**
>
> In term logic (a branch of philosophical logic), the square of opposition is a diagram representing the relations between the four basic categorical propositions.
> The origin of the square can be traced back to Aristotle's tractate On Interpretation and its distinction between two oppositions: contradiction and contrariety.
> However, Aristotle did not draw any diagram; this was done several centuries later by Apuleius and Boethius.
> In traditional logic, a proposition (Latin: propositio) is a spoke...

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/4 "2006-08-09T19:59:16Z")

</div>

Andre N. wrote:

> =\> true
> 
> Is there any reasoning for Enumerable#all? to always return true for  
> empty arrays?

I think they are modeled after universal and existential quantifiers in  
predicate calculus:

a.all?(&b) is true iff for all x in a b[x].

This leads to a.all? being true.

a.any?(&b) is true iff there exists an x in a for which b[x].

This leads to a.any? being false.

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/5 "2006-08-09T20:05:16Z")

</div>

On Thu, Aug 10, 2006 at 01:41:48AM +0900, Andre N. wrote:

> Is there any reasoning for Enumerable#all? to always return true for  
> empty arrays?

a.all?{ … } == true

can be read as “All elements in a satisfy { … }”, which we can  
interpret as  
“there is no element in a such that { … } is not satisfied”, which is  
obviously true if a is empty.

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 9, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/6 "2006-08-09T20:29:18Z")

</div>

On Thu, 2006-08-10 at 03:03 +0900, Mauricio F. wrote:

> can be read as “All elements in a satisfy { … }”, which we can interpret as  
> “there is no element in a such that { … } is not satisfied”, which is  
> obviously true if a is empty.

OK, thank you all for the explanations 🙂

Andre

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 23, 2006, 2:34am UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/7 "2006-08-23T02:34:17Z")

</div>

On Thu, Aug 10, 2006 at 08:55:12AM +0900, Just Another Victim of the  
Ambient M. wrote:

> > =\> true  
> > say the condition is true…  
> > unless mathematician.is\_an :intuitionist # (pretty rare)

Sorry I couldn’t resist  
-JÃ¼rgen

---

<div class="post-metadata">

**Author:** ![reflex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@reflex](https://www.ruby-forum.com/u/reflex)\
**Post date:** [August 10, 2006, 1:56am UTC](https://www.ruby-forum.com/t/enumerable-all-and-empty-arrays/64518/8 "2006-08-10T01:56:42Z")

</div>

“Andre N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> Is there any reasoning for Enumerable#all? to always return true for  
> empty arrays?

```
It's mathematically consistent.

You may be surprised to hear this but mathematicians are generally

```

optimists. Thus, if a condition is “vacuously satisfied,” then we  
generally  
say the condition is true…
