Quine: Difference between revisions
Content added Content deleted
(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: | Line 3,495: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Found online: |
Found online: |
||
<lang ruby>_="_=%p;puts _%%_";puts _%_</lang> |
|||
A shell session demonstrating that it is valid: |
|||
<pre>$ ruby -e '_="_=%p;puts _%%_";puts _%_' |
<pre>$ ruby -e '_="_=%p;puts _%%_";puts _%_' |
||
_="_=%p;puts _%%_";puts _%_ |
_="_=%p;puts _%%_";puts _%_ |
||
Line 3,500: | Line 3,503: | ||
_="_=%p;puts _%%_";puts _%_</pre> |
_="_=%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> |
<lang ruby>x = "x = %p; puts x %% x"; puts x % x</lang> |
||
The < |
The <code>%p</code> specifier outputs the result of calling the <code>.inspect</code> method on the argument. |
||
Even shorter (by a few characters): |
|||
<lang ruby>puts <<e*2,'e' |
<lang ruby>puts <<e*2,'e' |
||
puts <<e*2,'e' |
puts <<e*2,'e' |
||
e</lang> |
e</lang> |
||
Perhaps the simplest: |
|||
<lang ruby>eval s="puts'eval s='+s.inspect"</lang> |
<lang ruby>eval s="puts'eval s='+s.inspect"</lang> |
||
Line 3,531: | Line 3,534: | ||
Using the method on Wikipedia (0.9-pre-compatible, does not compile on Rust 1.0.0 and newer): |
Using the method on Wikipedia (0.9-pre-compatible, does not compile on Rust 1.0.0 and newer): |
||
<lang rust> |
<lang rust>fn main() |
||
fn main() |
|||
{ |
{ |
||
let q = 34u8; |
let q = 34u8; |
||
Line 3,590: | Line 3,592: | ||
i+=1; |
i+=1; |
||
} |
} |
||
⚫ | |||
} |
|||
⚫ | |||
A quine in the shape of a circle: |
A quine in the shape of a circle: |