Skip to content

Instantly share code, notes, and snippets.

@whiz25
Last active May 13, 2020 12:17
Show Gist options
  • Save whiz25/52b98e48ed7462fd7b5863152f287fc0 to your computer and use it in GitHub Desktop.
Save whiz25/52b98e48ed7462fd7b5863152f287fc0 to your computer and use it in GitHub Desktop.
- [ ] should be identical and returns the same thing as ruby's [`none?`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-none-3F). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_none.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] when a class is passed as an argument returns true if none of the collection is a member of such class
```ruby
array = Array.new(100) { rand(0...9) }
array.my_none?(String) == true #true
```
- [ ] when a pattern other than Regex or a Class is given returns true only if none of the collection matches the pattern
```ruby
words = %w[dog door rod blade]
words.my_none?(5) == words.none?(5) #true
```
- [ ] Regex is passed as an argument returns true only if none of the collection matches the Regex
```ruby
words.my_none?(/z/) == words.none?(/z/) #true
words.my_none?(/d/) == words.none?(/d/) #true
```
- [ ] returns true if the block never returns true for all elements
```ruby
true_array = [nil, false, true, []]
false_array = [nil, false, nil, false]
false_array.my_none? #true
true_array.my_none? #false
```
- [ ] when no block or argument is given when no block or argument is given returns true only if none of the collection members is true
```ruby
true_array = [nil, false, true, []]
false_array = [nil, false, nil, false]
false_array.my_none? == true #true
true_array.my_none? == false #false
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment