Ben Emson

Ruby Quine Example

I was recently challenged to write a quine in the language of my choice. If you are unsure what a quine is you can find out from http://en.wikipedia.org/wiki/Quine_(computing). However basically in our case it is a piece of code that when executed creates a copy of itself. This copy can then be executed and ad infinitum.

There are some official rules about how a quine should be implemented:

Anyway here is my solution in Ruby...

lambda{|x| puts x + x.inspect}.call "lambda{|x| puts x + x.inspect}.call"

Here is a brief description of what is happening. The lambda creates an anonymous function that takes one parameter and outputs it's value

Officially I think passing a value into the lambda x attribute violates one of the rules - but non-the-less it is quite a clear example and may be useful to get an idea of how a quine works.

Links

Here is a list of interesting links that might help, good luck: