Queueによるcoroutineもどき

require 'thread'

class Coroutine
  def initialize(&block)
    raise 'block not given' unless block_given?

    @q = Queue.new

    @th = Thread.start do
      @q.pop
      block.call(self)
    end
  end

  def yield
    @q.pop
  end

  def resume(*args)
    @q.push(args)
  end
end

coroutine = Coroutine.new do |c|
  loop do
    %w(春 夏 秋 冬).each do |i|
      puts i
      c.yield
    end
  end
end

while gets
  coroutine.resume
end