Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Enumerator#size

e.size → int, Float::INFINITY or nil

Returns the size of the enumerator, or nil if it can’t be calculated lazily.

Example
(1..100).to_a.permutation(4).size # => 94109400
loop.size # => Float::INFINITY
(1..100).drop_while.size # => nil
See also #rewind #with_index #peek_values #with_object also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0