Is there any Enumerable#count method shorthand?

I hope I’m not missing something obvious, but I couldn’t find a shorthand way to call .count on an Enumerable, i.e. Array (docs). Only .count { true } would work for me and I was hoping there’s a way to make this shorter.

1 Like

You probably just want to call .size. Most types that include Enumerable override the default implementation (which is just count { true }) to implement it in a more efficient way.

ref: Enumerable(T) - Crystal 1.7.2

1 Like

That’s exactly what I needed. Can’t believe I missed that (or misused it somehow) from the docs. Thanks for the help!