From: "atlas (Atlas Prime)" Date: 2013-11-23T03:58:35+09:00 Subject: [ruby-core:58506] [ruby-trunk - misc #9136] Deprecated Enumerator.new(object, method) bad for BasicObject Issue #9136 has been updated by atlas (Atlas Prime). @nobu I found that out but it seems kind of hackish way to have to do it. (Also a little counter-intuitive since Kernel is not in BasicObject). I ended up with: def to_enum(meth=:each) Enumerator.new{ |y| __send__(meth) { |*a| y.yield *a } } end Which seems to work, though I do not like so much using __send__. Is it not good to have Enumerator.new(object, method) ? Maybe it can be different constructor, e.g. Enumerator.for(object, method) ? ---------------------------------------- misc #9136: Deprecated Enumerator.new(object, method) bad for BasicObject https://bugs.ruby-lang.org/issues/9136#change-43090 Author: atlas (Atlas Prime) Status: Assigned Priority: Normal Assignee: zzak (Zachary Scott) Category: core Target version: =begin Documentation it says: In the second, deprecated, form, a generated Enumerator iterates over the given object using the given method with the given arguments passed. Use of this form is discouraged. Use Kernel#enum_for or Kernel#to_enum instead. e = Enumerator.new(ObjectSpace, :each_object) #-> ObjectSpace.enum_for(:each_object) But (({#enum_for})) and (({#to_enum})) are not available to subclasses of (({BasicObject})). In fact, I was defining (({#to_enum})) for a class that is a subclass of (({BasicObject})), and now I get warning of deprecation. =end -- http://bugs.ruby-lang.org/