raja / cs.indiana.edu (Raja S.) wrote:
>
>"Ben Tilly" <ben_tilly / hotmail.com> writes:
>
> > For those who don't know, a quine is a program that
> > prints its own source-code. [...]
>
> > They have entries in lots of languages, but none in
> > Ruby.  I suspect a few here might enjoy fixing that...
>
>A short one in Ruby would be:
>
>DATA.rewind
>puts DATA.read
>__END__
>
>
>% wc -c quine.rb
>      35 quine.rb
>
A shorter one in Ruby would be:


Now *that*'s short!  No characters! :-)

/duck

Seriously, reading your own source is usually considered
cheating.  And indeed if you try to put yours into the
command line, it will fail to seek.  OTOH the following
variation works from the command line...

# A Quine two!
s = DATA.readline(nil)
print s + s
__END__
# A Quine two!
s = DATA.readline(nil)
print s + s
__END__

And then we have classics like:

_=%q(puts"_=%q(#{_});eval _;");eval _;

(Translated from Perl.)

Cheers
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com