Permalink
Browse files

Better fix for deprecation of Enumerator.new.

  • Loading branch information...
1 parent e2cd323 commit 7816a875351b8c7930032116260495d642ad3075 @trans trans committed Nov 21, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/ostruct2.rb
View
11 lib/ostruct2.rb
@@ -321,12 +321,13 @@ def to_h
#
# @return [Enumerator]
#
- def to_enum
+ def to_enum(methname=:each!)
# Why has Ruby 2 deprecated this form?
- if ::RUBY_VERSION >= "2.0"
- ::Kernel.instance_method(:to_enum).bind(self).call(:each!)
- else
- ::Enumerator.new(self, :each!)
+ #::Enumerator.new(self, methname)
+ ::Enumerator.new do |y|
+ __send__(methname) do |*a|
+ y.yield *a
+ end
end
end

0 comments on commit 7816a87

Please sign in to comment.