Sha256: 1c6e968e8a7230f33060b22fc2e6fcd106566867eeccd998bee34cf27b70d7e2

Contents?: true

Size: 642 Bytes

Versions: 1

Compression:

Stored size: 642 Bytes

Contents

class Array
  # TOREMOVE after ruby 2.7.0
  def tally
    each_with_object(Hash.new(0)) { |v, h| h[v] += 1 }
  end

  def deep_merge_hashes
    self.inject({}) do |res, h|
      raise Exception.new("Not a hash #{h}") unless h.is_a?(Hash)
      h.deep_merge(res)
    end
  end

  def mean
    return 0 if size == 0
    inject(:+) / size
  end

  def without!(*values)
    ActiveSupport::Deprecation.warn('Array#without! is deprecated without replacement')
    values.flatten.each { |value| self.delete(value) }
    self
  end

  def contain?(other)
    (other - self).empty?
  end

  def intersect?(other)
    !(self & other).empty?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ab_admin-0.9.0 lib/ab_admin/core_ext/array.rb