Skip to content

Instantly share code, notes, and snippets.

@phaedryx
Last active December 19, 2015 20:49
Show Gist options
  • Save phaedryx/6015805 to your computer and use it in GitHub Desktop.
Save phaedryx/6015805 to your computer and use it in GitHub Desktop.
a rotator for Jeff
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