All pastes #263987 Raw Edit

Stuff

public ruby v1 · immutable
·published 2006-12-02 00:00 UTC
rendered paste body
#!/usr/bin/env rubyabort("Usage: quineit.rb INFILE [OUTFILE]") if ARGV.length < 1 or ARGV.length > 2input = ARGV[0]s = String.newt = String.newbang = String.newFile.open(input) do |file|    while line = file.gets        next if line.nil?        bang = line + "\n" and next if line =~ /#!/ #Can't put stuff before #!/usr/...        s << line.inspect[1...-1] #Escape (but don't include the quotes        t << line    endendlen = bang.inspect[1...-1].lengthf = (12 + len).to_se = (13 + len).to_sout = ARGV[1] ? File.open(ARGV[1], "w") : STDOUT #Writing to file or stdout?out.print bangout.puts "def quine"out.puts "\ts = \"" + bang.inspect[1...-1] + "def quine\\n\\ts = \\n\\ts[0..#{f}] + s.inspect + s[#{e}..-1]\\nend\\n#{s}\""out.puts "\ts[0..#{f}] + s.inspect + s[#{e}..-1]"out.puts "end"out.puts tout.close unless out == STDOUT