One minute
Ruby’s Kernel#itself Method
Kernel#itself
method simply yields the object that it was called on:
1.itself
=> 1
You can group an array by an amount of occurrences like this:
[1, 2, 2, 3, 4, 5, 6].group_by { |item| item }
Or like this, using Kernel#itself:
[1, 2, 2, 3, 4, 5, 6].group_by(&:itself)
Read other posts
comments powered by Disqus