Sha256: f1715303c05f36d218e06d599440e539d55ea7cb435f056019483a1abf8b30d9

Contents?: true

Size: 611 Bytes

Versions: 1

Compression:

Stored size: 611 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
        self - elements.flatten
      end

      def include *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

1 entries across 1 versions & 1 rubygems

Version Path
refinements-7.13.0 lib/refinements/arrays.rb