1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 15:48:01 +00:00

Add Are They All True as a ruby til.

This commit is contained in:
jbranchaud
2015-04-16 08:00:16 -05:00
parent 16152d0b46
commit 52e631ad3d
2 changed files with 24 additions and 0 deletions

23
ruby/are-they-all-true.md Normal file
View File

@@ -0,0 +1,23 @@
# 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:
```ruby
> [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:
```ruby
> employees.all?(&:salaried?)
# true
> [1,2,3,4,5].all?(&:odd?)
# false
```