Class: Array
Instance Method Summary collapse
- #contain?(other) ⇒ Boolean
- #deep_merge_hashes ⇒ Object
- #intersect?(other) ⇒ Boolean
- #mean ⇒ Object
-
#tally ⇒ Object
TOREMOVE after ruby 2.7.0.
- #without!(*values) ⇒ Object
Instance Method Details
#contain?(other) ⇒ Boolean
25 26 27 |
# File 'lib/ab_admin/core_ext/array.rb', line 25 def contain?(other) (other - self).empty? end |
#deep_merge_hashes ⇒ Object
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
29 30 31 |
# File 'lib/ab_admin/core_ext/array.rb', line 29 def intersect?(other) !(self & other).empty? end |
#mean ⇒ Object
14 15 16 17 |
# File 'lib/ab_admin/core_ext/array.rb', line 14 def mean return 0 if size == 0 inject(:+) / size end |
#tally ⇒ Object
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 |