Created
May 2, 2017 13:49
-
-
Save davidbalbert/b61beac29a3e10604e27d355e83e02b3 to your computer and use it in GitHub Desktop.
Powers of two
This file contains hidden or 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 PowersOfTwo | |
| include Enumerable | |
| class << self | |
| include Enumerable | |
| def each(&block) | |
| new.each(&block) | |
| end | |
| end | |
| def initialize | |
| @n = 1 | |
| end | |
| def each | |
| return to_enum unless block_given? | |
| loop do | |
| yield 2**@n | |
| @n += 1 | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment