Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created September 9, 2011 18:33
Show Gist options
  • Select an option

  • Save practicingruby/1206966 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/1206966 to your computer and use it in GitHub Desktop.
class MyEnumerator
include Enumerable
def initialize(target, *iterator)
@target = target
@iterator = iterator
end
def each(&block)
@target.send(*@iterator, &block)
end
end
module Cue
def self.each_word(text)
if block_given?
text.split(/ /).each { |w| yield(w) }
else
MyEnumerator.new(self, :each_word, text)
end
end
end
p Cue.each_word("this is a sentence").map { |x| x.reverse }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment