Ruby Enumerable tally
For the Advent of Code, I was curious if there was a good way to do this in one line (no technical reason, just because...)Not sure why, but it dawned on me this was likely something that Ruby would have built in (again, just because). It turns out in Ruby 2.7, the tally method was added to Enumerable.Tallies the collection, i.e., counts the occurrences of each element. Returns a hash with the elements of the collection as keys and the corresponding counts as values.
Ruby Enumerable tally #ruby #rails #rubyonrails #bosnia #programming #tutorials #rubydeveloper #railsdeveloper