Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 544 Bytes

are-they-all-true.md

File metadata and controls

23 lines (19 loc) · 544 Bytes

Are They All True?

There is a method on Enumerable that allows you to check against everything in a collection. This is the all? method. For instance, if you want to check if an array of values are all true, you can call it without arguments:

> [true, true, true].all?
# true
> [true, false, true].all?
# false

You can also pass it a block which is helpful if you want to check an attribute or method on a collection of objects, like so:

> employees.all?(&:salaried?)
# true
> [1,2,3,4,5].all?(&:odd?)
# false