diff --git a/README.md b/README.md index 2a3984b..f6ddd25 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ smart people at [Hashrocket](http://hashrocket.com/). ### ruby +- [Are They All True?](ruby/are-they-all-true.md) - [Create an Array of Stringed Numbers](ruby/create-an-array-of-stringed-numbers.md) - [Limit Split](ruby/limit-split.md) - [Parallel Bundle Install](ruby/parallel-bundle-install.md) diff --git a/ruby/are-they-all-true.md b/ruby/are-they-all-true.md new file mode 100644 index 0000000..f5ca112 --- /dev/null +++ b/ruby/are-they-all-true.md @@ -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 +```