Ruby:打印源代码

发布于 2024-10-12 05:31:18 字数 259 浏览 4 评论 0原文

最近我听说了一个叫蒯因的东西。但我对它的定义有点不清楚。

我相信您可以在不使用 __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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2024-10-19 05:31:18

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

成熟的代价 2024-10-19 05:31:18

这些东西不应该被称为“奎因”,而应该被称为“哥德尔”或“哥德尔”,因为(至少在我看来)通常用于实现这种效果的技术被用在哥德尔对第一不完备性定理的证明中(参见库尔特·哥德尔的全集 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文