A Quine Is A Quine Is A Quine

After re-reading Ken Thompson’s Reflections on Trusting Trust, I decided to write a Ruby quine.

A quine is a “program that generates a copy of its own source text as its complete output.” I decided to use the classic Lisp quine as a foundation.

(lambda (x) (list x (list (quote quote) x))) (quote (lambda (x) (list x (list (quote quote) x)))))

This is what I came up with:

def x(s); puts %Q{#{s} x(%q{#{s}})}; end; x(%q{def x(s); puts %Q{#{s} x(%q{#{s}})}; end;})

The Quine Page doesn’t have any Ruby Quines, but there are a bunch on the Ruby Quines page. If you remove the extra spaces from my quine, it’s 84 characters. The shortest Ruby quine known is 28 characters:

puts <<2*2,2
puts <<2*2,2
2

Pretty cute!