Class: Array

Inherits:
Object show all
Defined in:
lib/ab_admin/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#contain?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ab_admin/core_ext/array.rb', line 25

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

#deep_merge_hashesObject



7
8
9
10
11
12
# File 'lib/ab_admin/core_ext/array.rb', line 7

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

#intersect?(other) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ab_admin/core_ext/array.rb', line 29

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

#meanObject



14
15
16
17
# File 'lib/ab_admin/core_ext/array.rb', line 14

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

#tallyObject

TOREMOVE after ruby 2.7.0



3
4
5
# File 'lib/ab_admin/core_ext/array.rb', line 3

def tally
  each_with_object(Hash.new(0)) { |v, h| h[v] += 1 }
end

#without!(*values) ⇒ Object



19
20
21
22
23
# File 'lib/ab_admin/core_ext/array.rb', line 19

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