mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user