mruby-enumerator: add Enumerator#size

If the original object responds to `size` method, `Enumerator#size` calls
that method, otherwise return `nil`. CRuby returns the exact size for
more cases (e.g. Enumerable::Lazy#size), but mruby has more limitations.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-10-02 00:15:01 +09:00
parent 49f86f19b2
commit 861f8bdfa9
@@ -238,6 +238,14 @@ class Enumerator
end
end
def size
if @size
@size
elsif @obj.respond_to?(:size)
@obj.size
end
end
##
# call-seq:
# enum.each { |elm| block } -> obj