mirror of
				https://github.com/red-data-tools/YouPlot.git
				synced 2025-10-31 16:28:17 +08:00 
			
		
		
		
	Add tally method for older rubies
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 kojix2
					kojix2