Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created July 31, 2019 18:21
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/393262a6e61499834026e7e2f5d4fd12 to your computer and use it in GitHub Desktop.
Save havenwood/393262a6e61499834026e7e2f5d4fd12 to your computer and use it in GitHub Desktop.
Enumerable and Enumerator examples for Technodrome on IRC
class Technodrome
include Enumerable
def each
yield :fee
yield :fi
yield :fo
yield :fum
end
end
Technodrome.new.map(&:to_s)
#=> ["fee", "fi", "fo", "fum"]
technodrome = Enumerator.new 4 do |yielder|
yielder << :fee
yielder << :fi
yielder << :fo
yielder << :fum
end
technodrome.map(&:to_s)
#=> ["fee", "fi", "fo", "fum"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment