Last active
May 6, 2020 16:16
-
-
Save whiz25/b537bfdca9a8eafb967ae1b0da392e52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- [ ] should be identical and returns the same thing as ruby's [`all?`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-all-3F). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_all.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2)) | |
- [ ] when no block or argument is given returns true when none of the collection members are false or nil | |
```ruby | |
true_array = [1, true, 'hi', []] | |
false_array = [1, false, 'hi', []] | |
true_array.my_all? == true_array.all? # should return true | |
``` | |
- [ ] when a class is passed as an argument returns true if all of the collection is a member of such class | |
```ruby | |
array = Array.new(100){rand(0...9)} | |
array.my_all?(Integer) == array.all?(Integer) | |
``` | |
- [ ] when a Regex is passed as an argument returns true if all of the collection matches the Regex | |
```ruby | |
words = %w[dog door rod blade] | |
words.my_all?(/d/) == words.all?(/d/) | |
``` | |
- [ ] when a pattern other than Regex or a Class is given returns true if all of the collection matches the pattern | |
```ruby | |
array.my_all?(3) == array.all?(3) # should return true | |
``` | |
- [ ] returns true if the block never returns false or nil | |
```ruby | |
true_block = proc { |num| num <= 9 } | |
false_block = proc { |num| num > 9 } | |
array.my_all?(&true_block) == array.all?(&true_block) # should return true | |
array.my_all?(&false_block) == array.all?(&false_block) # should return true | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment