diff options
| author | Jun Hiroe <[email protected]> | 2014-03-23 12:58:12 +0900 |
|---|---|---|
| committer | Jun Hiroe <[email protected]> | 2014-03-23 12:58:12 +0900 |
| commit | 1f709c1ef0d304f200c836c4b0a95c2516e6b7fa (patch) | |
| tree | a77880885f4c97421745fe37cbd57f9fa2136992 /mrbgems/mruby-enum-ext/mrblib/enum.rb | |
| parent | ff6666632f96fe837cc36b13afac8f2ab147d9d7 (diff) | |
| download | mruby-1f709c1ef0d304f200c836c4b0a95c2516e6b7fa.tar.gz mruby-1f709c1ef0d304f200c836c4b0a95c2516e6b7fa.zip | |
Add Enumerable#none?
Diffstat (limited to 'mrbgems/mruby-enum-ext/mrblib/enum.rb')
| -rw-r--r-- | mrbgems/mruby-enum-ext/mrblib/enum.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb index 8a2cdd5f1..8b62cf057 100644 --- a/mrbgems/mruby-enum-ext/mrblib/enum.rb +++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb @@ -413,4 +413,27 @@ module Enumerable end [min, max] end + + ## + # call-seq: + # enum.none? [{ |obj| block }] -> true or false + # + # Passes each element of the collection to the given block. The method + # returns <code>true</code> if the block never returns <code>true</code> + # for all elements. If the block is not given, <code>none?</code> will return + # <code>true</code> only if none of the collection members is true. + # + # %w(ant bear cat).none? { |word| word.length == 5 } #=> true + # %w(ant bear cat).none? { |word| word.length >= 4 } #=> false + # [].none? #=> true + # [nil, false].none? #=> true + # [nil, true].none? #=> false + + def none?(&block) + self.each do |val| + val = block.call(val) if block + return false if val + end + true + end end |
