Yusuke Endoh's Qlobe: A Rotating Quine in Ruby
Ruby core team member Yusuke Endoh published a quine called Qlobe that outputs a rotated version of itself. Each execution shifts the code by 45 degrees, and an integer argument sets any angle.
The program
On September 5, 2010, Yusuke Endoh, a member of the Ruby core team, published a quine called Qlobe on his blog. The program outputs a copy of its own source code, but the text is rotated 45 degrees. Running the program eight times brings the output back to the original orientation. Endoh noted that passing an integer as a command-line argument sets any desired rotation angle.
The code relies on eval to execute a string, and a variable v holds the current rotation angle. One reader explained that about half of the program contains a compressed map of the Earth. After unpacking, each line is rotated according to v, distorted into shape, and converted to ASCII for printing. Several tricks ensure that this map data is neither executed as code nor stored as data.
Running the quine
Some users reported a syntax error when running the program with Ruby 1.9.1p378. Endoh responded that he had tested it with Ruby 1.8.7-p72 and 1.9.2-p0. Another commenter pointed out that executing the file directly (./earthrotate.rb) could fail, and suggested using ruby earthrotate.rb instead. Alexander Repty created a YouTube video showing the rotation effect. Various loop commands appeared in the comments, such as while true; do clear; ruby a.rb | tee b.rb; sleep 1; mv -f b.rb a.rb; done and watch -n1 'ruby current.rb | tee next.rb && mv next.rb current.rb'.
Another user ran the program with Ruby 1.8.1 and saw a warning about parenthesizing arguments, though the program still worked. A commenter posted a loop to rotate through all angles: for ((;;)); do for i in {1..360}; do clear; ruby qlobe.rb $i; sleep 0.1; done; done. Another variation used tput cup 0 0 to reduce flickering.
Background
Endoh wrote that his previous quines were sometimes specialized for Japanese. To attend RubyConf, he decided to write a “global” quine. The blog post includes a note that the text was translated from Japanese. The code examples show different initial values for v, such as v=0000 and v=0416, which correspond to different starting rotations.