class Fixnum def double_upto(stop) x = self until x > stop yield x x = x * 2 end end end 10.double_upto(50) { |x| puts x } # 10 # 20 # 40