Calculating PI in Ruby

Here's my Ruby implementation of the simple Haskell algorithm as given on page 2 of An Unbounded Spigot Algorithm for the Digits of Pi:

def pi_digits
  q, r, t, k = 1, 0, 1, 1
  loop do
    n = (3*q+r) / t
    if (4*q+r) / t == n
      yield n
      q, r, t, k = 10*q, 10*(r-n*t), t, k
    else
      q, r, t, k = q*k, q*(4*k+2)+r*(2*k+1), t*(2*k+1), k+1
    end
  end
end

pi_digits {|n| print n; $stdout.flush }

The algorithm generates an infinite number of digits of Pi and prints each digit to STDOUT.

The code itself is from an old post of mine which dates back to November 25th, 2003. It is remarkable that, even 23 years and 3 major releases of Ruby later, the code just runs fine without any modifications.