mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Check method existence in `to_enum'; ref #3773
This commit is contained in:
@@ -43,6 +43,9 @@ class Enumerator
|
||||
end
|
||||
|
||||
def to_enum(meth=:each, *args, &block)
|
||||
unless self.respond_to?(meth)
|
||||
raise NoMethodError, "undefined method #{meth}"
|
||||
end
|
||||
lz = Lazy.new(self, &block)
|
||||
lz.obj = self
|
||||
lz.meth = meth
|
||||
|
||||
@@ -115,6 +115,9 @@ class Enumerator
|
||||
else
|
||||
raise ArgumentError unless obj
|
||||
end
|
||||
if @obj and !self.respond_to?(meth)
|
||||
raise NoMethodError, "undefined method #{meth}"
|
||||
end
|
||||
|
||||
@obj = obj
|
||||
@meth = meth
|
||||
|
||||
Reference in New Issue
Block a user