Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created April 18, 2018 06:54
Show Gist options
  • Save a2ikm/ec242106c98814f09b8517bd3f0d079e to your computer and use it in GitHub Desktop.
Save a2ikm/ec242106c98814f09b8517bd3f0d079e to your computer and use it in GitHub Desktop.
Fiberの1回目のresumeでとりあえずブロック処理に突入させる
fib = Fiber.new do
Fiber.yield # y1
a, b = 1, 1
while true
Fiber.yield(a) # y2
a, b = b, a + b
end
end
fib.resume # y1まで進める
10.times do |n|
p [n, fib.resume] # y2を処理する
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment