Ruby: Print source code
Recently I heard about something called Quine. But my definition of it is a bit unclear.
I believe that you can print your own Ruby file's source code without using __FILE__
? Is that possible? I would be very interested in your ideas. I would like to test that out. Dunno, get the source 开发者_JS百科of the code below:
class MyClass
def initialize
print "You cannot read me!!"
end
end
So I can print that whole class?
A Quine is a program that prints out its own source code as its only functionality and yes you can do this without reading the source code file. The real challenge, and fun, is to write as short a Quine as possible.
The above would not be a Quine because it doesn't print its own source code out and it couldn't be because it does more than just output its own code.
Check out this thread:
Shortest Ruby Quine
Such things should not be called "Quines" but "Gödels" or "Goedels" because (at least so it appears to me) the technique commonly used to achieve that effect is used in Gödel's proof of the First Incompleteness Theorem (cf. Kurt Gödel's Collected Works I, p.175) which came before Quine's discussions.
精彩评论