Jump to content

Quine: Difference between revisions

132 bytes added ,  3 years ago
Ruby: improve wording and formatting; Rust: improve formatting
(Ruby: delete the more verbose file-reading example, as the next example is equivalent and simpler)
(Ruby: improve wording and formatting; Rust: improve formatting)
Line 3,495:
=={{header|Ruby}}==
Found online:
<lang ruby>_="_=%p;puts _%%_";puts _%_</lang>
 
A shell session demonstrating that it is valid:
<pre>$ ruby -e '_="_=%p;puts _%%_";puts _%_'
_="_=%p;puts _%%_";puts _%_
Line 3,500 ⟶ 3,503:
_="_=%p;puts _%%_";puts _%_</pre>
 
A more readable version of the above example:
more readably:
<lang ruby>x = "x = %p; puts x %% x"; puts x % x</lang>
The <ttcode>%p</ttcode> specifier outputs the result of calling the <ttcode>.inspect</ttcode> method on the argument.
 
evenEven shorter (by a few characters):
<lang ruby>puts <<e*2,'e'
puts <<e*2,'e'
e</lang>
 
perhapsPerhaps the simplest:
<lang ruby>eval s="puts'eval s='+s.inspect"</lang>
 
Line 3,531 ⟶ 3,534:
 
Using the method on Wikipedia (0.9-pre-compatible, does not compile on Rust 1.0.0 and newer):
<lang rust>fn main()
fn main()
{
let q = 34u8;
Line 3,590 ⟶ 3,592:
i+=1;
}
}</lang>
}
</lang>
 
A quine in the shape of a circle:
21

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.