Ruby:打印源代码 [英] Ruby: Print source code

查看:127
本文介绍了Ruby:打印源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我听说了一种叫Quine的东西.但是我对此的定义还不清楚.

Recently I heard about something called Quine. But my definition of it is a bit unclear.

我相信您可以在不使用__FILE__的情况下打印自己的Ruby文件的源代码?那可能吗?我会对您的想法很感兴趣.我想测试一下. Dunno,获取以下代码的来源:

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?

推荐答案

Quine是一个程序,它打印出自己的源代码作为其唯一功能,是的,您可以在不读取源代码文件的情况下执行此操作.真正的挑战和乐趣是,写尽可能短的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.

以上内容不是Quine,因为它不会打印出自己的源代码,也不会因为不仅仅输出自己的代码而已.

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.

查看此线程:
最短的Ruby Quine

Check out this thread:
Shortest Ruby Quine

这篇关于Ruby:打印源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆