From 78559b989e500311e38a54679fd205fe4af74342 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Mon, 3 Aug 2020 10:44:49 +0900 Subject: [PATCH] Add tally method for older rubies --- lib/uplot/command.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/uplot/command.rb b/lib/uplot/command.rb index 415d818..53743ea 100644 --- a/lib/uplot/command.rb +++ b/lib/uplot/command.rb @@ -205,3 +205,14 @@ module Uplot 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