Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ruby have an array sum method for boolean values?

Ruby allows you to do

[5,5,5].sum
=> 15

Is there anything for doing boolean arithmetic on an array like

[true, true, true].sum
=> true
[true, false, true].sum
=> false
like image 906
biagidp Avatar asked Oct 19 '14 20:10

biagidp


1 Answers

[true, true, true].all?

will return true.

[true, false, true].all?

will return false.

Furthermore, if you want to boolean OR the values:

[true, false, true].any? 

returns true.

like image 99
mcfinnigan Avatar answered Oct 18 '22 07:10

mcfinnigan