Skip to content

Instantly share code, notes, and snippets.

@domgetter
Last active January 12, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domgetter/dd238e1dc4a78922176d to your computer and use it in GitHub Desktop.
Save domgetter/dd238e1dc4a78922176d to your computer and use it in GitHub Desktop.
class Object
def repeatedly
Enumerator.new do |y|
loop { y << yield(self) }
end
end
end
[3,4,5].repeatedly(&:sample).take(10)
#=> [4, 3, 4, 4, 4, 4, 3, 5, 5, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment