Skip to content

Commit

Permalink
Clear the Enumerator#peek lookahead value on #rewind
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdowney committed Oct 23, 2011
1 parent 6345f32 commit 06188b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 0 additions & 9 deletions kernel/common/enumerator.rb
Expand Up @@ -158,15 +158,6 @@ def reset
end
end
end

# Rewinds the enumeration sequence by the next method.
#
# If the enclosed object responds to a "rewind" method, it is called.
#
def rewind
@generator.rewind if @generator
self
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions kernel/common/enumerator18.rb
Expand Up @@ -33,5 +33,14 @@ def next

raise StopIteration, "iteration reached end"
end

# Rewinds the enumeration sequence by the next method.
#
# If the enclosed object responds to a "rewind" method, it is called.
#
def rewind
@generator.rewind if @generator
self
end
end
end
10 changes: 10 additions & 0 deletions kernel/common/enumerator19.rb
Expand Up @@ -73,6 +73,16 @@ def peek
item
end

# Rewinds the enumeration sequence by the next method.
#
# If the enclosed object responds to a "rewind" method, it is called.
#
def rewind
@generator.rewind if @generator
@lookahead = []
self
end

# A supporting class for Enumerator that allows for easy proxying to a Generator's yield.
class Yielder
def initialize(&block)
Expand Down

0 comments on commit 06188b4

Please sign in to comment.