Created
July 31, 2019 18:21
-
-
Save havenwood/393262a6e61499834026e7e2f5d4fd12 to your computer and use it in GitHub Desktop.
Enumerable and Enumerator examples for Technodrome on IRC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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