Skip to content

Commit

Permalink
Better fix for deprecation of Enumerator.new.
Browse files Browse the repository at this point in the history
  • Loading branch information
trans committed Nov 21, 2013
1 parent e2cd323 commit 7816a87
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/ostruct2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7816a87

Please sign in to comment.