mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 15:11:12 +08:00
Add tally method for older rubies
This commit is contained in:
parent
d069f8af23
commit
78559b989e
@ -205,3 +205,14 @@ module Uplot
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# backports
|
||||||
|
# https://github.com/marcandre/backports/blob/master/lib/backports/2.7.0/enumerable/tally.rb
|
||||||
|
unless Enumerable.method_defined? :tally
|
||||||
|
module Enumerable
|
||||||
|
def tally
|
||||||
|
# NB: By spec, tally should return default-less hash
|
||||||
|
each_with_object(Hash.new(0)) { |item, res| res[item] += 1 }.tap { |h| h.default = nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user