Last active
December 4, 2022 18:57
-
-
Save composerinteralia/a2abdbda01c249aaaf96a58d25127361 to your computer and use it in GitHub Desktop.
Quine about quines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quines are programs that print their own source code | |
# This program is a quine that explains how some Ruby quines work | |
# This first one uses a heredoc with 2 as the delimiter | |
# The beginning of the program appears twice (before and inside the heredoc) | |
# Then it puts the string twice (* 2) and puts 2 | |
puts <<2*2,2 | |
# Quines are programs that print their own source code | |
# This program is a quine that explains how some Ruby quines work | |
# This first one uses a heredoc with 2 as the delimiter | |
# The beginning of the program appears twice (before and inside the heredoc) | |
# Then it puts the string twice (* 2) and puts 2 | |
puts <<2*2,2 | |
2 | |
# eval a string that prints the beginning of the program and then inspects _ | |
# Assign the string to _ so it inspects itself. | |
eval _="print '\n# eval a string that prints the beginning of the program and then inspects _\n# Assign the string to _ so it inspects itself.\neval _=';p _" | |
# String starts with the beginning of the program, uses the c format specifier | |
# to turn ords into chars (34 for double quote and 10 for newline), and s | |
# for the string itself, and includes the end of the program | |
# Assign the string to a variable and then format print it with itself. | |
_=" | |
# String starts with the beginning of the program, uses the c format specifier | |
# to turn ords into chars (34 for double quote and 10 for newline), and s | |
# for the string itself, and includes the end of the program | |
# Assign the string to a variable and then format print it with itself. | |
_=%c%s%c; printf _,34,_,34,10%c | |
"; printf _,34,_,34,10 | |
# String starts with the beginning of the program, uses p format specifier to | |
# inspect the arg, and ends with a percent-escaped end of the program | |
# Assign the string to a variable, and format it with itself | |
_="# String starts with the beginning of the program, uses p format specifier to\n# inspect the arg, and ends with a percent-escaped end of the program\n# Assign the string to a variable, and format it with itself\n_=%p;puts _%%_\n";puts _%_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment