Hello.

This is my first rubyquiz, and I am still learning Ruby. I decided to
go with something simple but fun. So I did a search on the CPAN (I've
used Perl before) for the Acme modules, and chose Acme::Bleach
(http://search.cpan.org/~dconway/Acme-Bleach-1.12/lib/Acme/Bleach.pm)
to implement. I couldn't find a Ruby version on either RAA or
rubyforge.

Acme::Bleach is a module by Damian Conway, and it literally bleaches
your program, whilst still leaving it in a runnable state. It's a
really cool little module, and I stuck as close to the original as
possible - even using nearly the same method names. Here it is in its
entirety. Any suggestions, criticisms, etc. are highly welcome.


#Ruby port of Acme::Bleach - by Amran Gaye
#You can use this by doing an "include 'Bleach' " at the top of your
program

$tie="\t"*8

def whiten(laundry)
  #Change laundry to binary 1s and 0s...
  #then change those to tab and space characters. Finally add newlines
after every 9th character
  result = laundry.unpack('b*').to_s.tr('01',"
\t").gsub(/(.{9})/,"\\1\n")
  return $tie + result        #Add a tie to the washed shirt, and
return it
end

def brighten(laundry)
  #Does the opposite of whiten
  laundry.sub!(/\t{8}/,'')    #Remove tie
  laundry.tr!("\n",'')    #Remove newlines
  laundry.tr(" \t",'01').to_a.pack('b*') #Change spaces and tabs to 0s
and 1s, then repack them as binary
end


def dirty?(laundry)           #Laundry is dirty only if it contains
non-space characters
  laundry =~ /\S/
end

def proper?(laundry)               #shirt is proper if it contains a
tie
  laundry =~ /^#$tie/
end


shirt = IO.readlines($0).to_s          #Read in current program
shirt.sub!("require 'Bleach'",'')      #Remove require line

if(not dirty?(shirt) and proper?(shirt))
  eval brighten(shirt)
else
  file = File.new($0,"w")
  file.puts("require 'Bleach'")
  file.puts(whiten(shirt))
  file.close
end