Sha256: 972666840cda44b3686081a7b20d36df0b43eff98fa220f8c252f9158b7c5774

Contents?: true

Size: 408 Bytes

Versions: 30

Compression:

Stored size: 408 Bytes

Contents

# frozen_string_literal: true

module Refinements
  module Shared
    module Enumerables
      # Provides shared functionality for knowing whether an enumerable has many elements or not.
      module Many
        def many?
          return size > 1 unless block_given?

          total = reduce(0) { |count, item| yield(item) ? count + 1 : count }
          total > 1
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
refinements-12.6.0 lib/refinements/shared/enumerables/many.rb
refinements-12.5.0 lib/refinements/shared/enumerables/many.rb
refinements-12.4.0 lib/refinements/shared/enumerables/many.rb
refinements-12.3.0 lib/refinements/shared/enumerables/many.rb
refinements-12.2.0 lib/refinements/shared/enumerables/many.rb
refinements-12.1.0 lib/refinements/shared/enumerables/many.rb
refinements-12.0.1 lib/refinements/shared/enumerables/many.rb
refinements-12.0.0 lib/refinements/shared/enumerables/many.rb
refinements-11.1.3 lib/refinements/shared/enumerables/many.rb
refinements-11.1.2 lib/refinements/shared/enumerables/many.rb
refinements-11.1.1 lib/refinements/shared/enumerables/many.rb
refinements-11.1.0 lib/refinements/shared/enumerables/many.rb
refinements-11.0.1 lib/refinements/shared/enumerables/many.rb
refinements-11.0.0 lib/refinements/shared/enumerables/many.rb
refinements-10.1.1 lib/refinements/shared/enumerables/many.rb
refinements-10.1.0 lib/refinements/shared/enumerables/many.rb
refinements-10.0.1 lib/refinements/shared/enumerables/many.rb
refinements-10.0.0 lib/refinements/shared/enumerables/many.rb
refinements-9.8.0 lib/refinements/shared/enumerables/many.rb
refinements-9.7.1 lib/refinements/shared/enumerables/many.rb