Last active
December 19, 2015 20:49
-
-
Save phaedryx/6015805 to your computer and use it in GitHub Desktop.
a rotator for Jeff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rotator_factory(*values) | |
Enumerator.new do |y| | |
loop do | |
y.yield values.first | |
values = values.rotate | |
end | |
end | |
end | |
r = rotator_factory('a','b','c') | |
r.next # => 'a' | |
r.next # => 'b' | |
r.next # => 'c' | |
r.next # => 'a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment