Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created March 6, 2020 16:48
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 havenwood/e09b8a980ba3378b03a9c2a7b4ec8170 to your computer and use it in GitHub Desktop.
Save havenwood/e09b8a980ba3378b03a9c2a7b4ec8170 to your computer and use it in GitHub Desktop.
My solution to phaul's kata mentioned in #ruby IRC: https://www.codewars.com/kata/59b7b7f0623654c2ce000021/ruby
module IterateString
refine String do
def iterate(count, &block)
Enumerator.produce(self, &block).first(count)
end
end
end
using IterateString
'str'.iterate(3) {|s| s * 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment