Sha256: bafd26ad80ccc8844f2c2068dc15d30d9c75de8f583aac1e24df44a2f09b8717

Contents?: true

Size: 907 Bytes

Versions: 5

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module Refinements
  module Arrays
    refine Array do
      def compress
        compact.reject(&:empty?)
      end

      def compress!
        replace compress
      end

      def exclude *elements
        warn "[DEPRECATION]: #exclude is deprecated, use #excluding instead."
        excluding(*elements)
      end

      def excluding *elements
        self - elements.flatten
      end

      def include *elements
        warn "[DEPRECATION]: #include is deprecated, use #including instead."
        including(*elements)
      end

      def including *elements
        self + elements.flatten
      end

      def intersperse *elements
        product([elements]).tap(&:pop).flatten.push last
      end

      def mean
        size.zero? ? 0 : sum(0) / size
      end

      def ring &block
        [last, *self, first].each_cons 3, &block
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
refinements-7.17.0 lib/refinements/arrays.rb
refinements-7.16.0 lib/refinements/arrays.rb
refinements-7.15.1 lib/refinements/arrays.rb
refinements-7.15.0 lib/refinements/arrays.rb
refinements-7.14.0 lib/refinements/arrays.rb