Ruby: Print source code

微笑、不失礼 提交于 2019-12-11 16:37:41

问题


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:


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




回答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.



来源:https://stackoverflow.com/questions/4719649/ruby-print-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!