Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created May 2, 2017 13:49
Show Gist options
  • Select an option

  • Save davidbalbert/b61beac29a3e10604e27d355e83e02b3 to your computer and use it in GitHub Desktop.

Select an option

Save davidbalbert/b61beac29a3e10604e27d355e83e02b3 to your computer and use it in GitHub Desktop.
Powers of two
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