Ruby:打印源代码
最近我听说了一个叫蒯因的东西。但我对它的定义有点不清楚。
我相信您可以在不使用 __FILE__
的情况下打印自己的 Ruby 文件的源代码?这可能吗?我对你的想法非常感兴趣。我想测试一下。不知道,获取下面代码的源代码:
class MyClass
def initialize
print "You cannot read me!!"
end
end
所以我可以打印整个课程?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Quine 是一个打印自己的源代码作为其唯一功能的程序,是的,您可以在不阅读源代码文件的情况下执行此操作。真正的挑战和乐趣是写尽可能短的蒯因。
上面的代码不会是 Quine,因为它不会打印自己的源代码,而且也不可能是 Quine,因为它不仅仅输出自己的代码。
查看此主题:
最短的 Ruby Quine
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
这些东西不应该被称为“奎因”,而应该被称为“哥德尔”或“哥德尔”,因为(至少在我看来)通常用于实现这种效果的技术被用在哥德尔对第一不完备性定理的证明中(参见库尔特·哥德尔的全集 I,第 175 页)出现在蒯因的讨论之前。
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.