Quine: Difference between revisions

1 byte removed ,  3 years ago
Ruby: delete the more verbose file-reading example, as the next example is equivalent and simpler
(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:
<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>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>
 
=={{header|Rust}}==
 
=={{header|Rust}}==
 
A short quine (works with Rust 1.3.0):
21

edits