size
size() -> Number
Returns the size of the enumeration.
Examples
$R(1, 10).size()
// -> 10
['hello', 42, true].size()
// -> 3
$H().size()
// -> 0
Performance considerations
This method exists solely to provide a generic size-getting behavior for all objects enumerable. The default implementation actually performs the loop, which means it has exact linear complexity. Most objects that mix in Enumerable
will try to optimize this by redefining their own version of size
; this is, for instance, the case of Array
, which redefines size
to delegate to arrays’ native length
property.