Check method existence in `to_enum'; ref #3773

This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-08-11 09:21:09 +09:00
parent ac42ccc1fc
commit 68470bef86
2 changed files with 6 additions and 0 deletions
+3
View File
@@ -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