Quine: Difference between revisions
Content deleted Content added
fix Ruby’s last two examples, which were incorrect |
Ruby: delete the more verbose file-reading example, as the next example is equivalent and simpler |
||
Line 3,512: | Line 3,512: | ||
<lang ruby>eval s="puts'eval s='+s.inspect"</lang> |
<lang ruby>eval s="puts'eval s='+s.inspect"</lang> |
||
An implementation that reads and prints the file the code is stored in (which violates some definitions of “quine”): |
|||
One (maybe a bit verbose) version, to be appended to the end of any file. This doesn't work in IRB, because it isn't a file. |
|||
<lang ruby> |
<lang ruby>puts open(__FILE__).read</lang> |
||
f = File.open __FILE__ |
|||
f.each_line do |line| |
|||
puts line |
|||
end |
|||
f.close |
|||
</lang> |
|||
As the above implementation depends on the code being saved in a file, it doesn’t work in IRB. |
|||
or |
|||
<lang ruby> |
|||
puts open(__FILE__).read |
|||
</lang> |
|||
⚫ | |||
⚫ | |||
A short quine (works with Rust 1.3.0): |
A short quine (works with Rust 1.3.0): |