0

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 of the code below:

class MyClass
  def initialize
    print "You cannot read me!!"
  end
end

So I can print that whole class?

1

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Well, I said Quine accidentally. I don't care about making the shortest Quine possible. All I want is a way to print my source code, no matter the size of whatever I need.
Ah, I wondered about that but you specifically said a Quine so... the answer is again yes. The problem comes if you're using Ruby 1.9 since it currently does not have native support for generating source code for dynamically generated code but there is a solution: Sourcify will generate (not exact) source code for procs (lambdas are now procs in 1.9 so them too).
-2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.