Module: Corefines::Enumerable::Many
- Defined in:
- lib/corefines/enumerable.rb
Instance Method Summary collapse
-
#many? ⇒ Object
Returns
trueif the enumerable has more than one element.
Instance Method Details
#many? ⇒ Boolean #many? {|obj| ... } ⇒ Boolean
Returns true if the enumerable has more than one element.
This method is functionally equivalent to enum.to_a.size > 1, or enum.select { ... }.length > 1 when the block is given.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/corefines/enumerable.rb', line 61 module Many Support.classes_including_module(::Enumerable) do |klass| refine klass do def many? cnt = 0 if block_given? any? do |element| cnt += 1 if yield element cnt > 1 end else any? { (cnt += 1) > 1 } end end end end end |