This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Cleaned in a Gross Way
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Florian Groà is disassembling and analyzing the obfuscated Ruby contest winners! No one can object to this.
His shovelings through James Edward Grey II’s Ruby Quiz Loader is great. He spots:
while $_ =~ /([^\n]{81,})/:
z = $1.dup;
f = $1.dup;
f[f.rindex(" ", 80), 1] = "\n";
f.sub!(/\n[ \t]+/, "\n");
sub!(/#{Regexp.escape(z)}/, f)
end
This is fairly nice code for rewrapping lines longer than 80 characters.
The while uses a regexp to iterate over all pieces of text that contain no newlines for more than 80 characters. (By the way, Jamis could have used ~regexp here as that will apply the regexp to $_ as well.) Note the colon at the end of the while â this is legal Ruby and confused the highlighter and made reformating the code quite hard…
First of all, this piece of code depends on the order that methods will be returned by Object#methods and I think that that order is not guaranteed to be stable â as far as I know it might basically change depending on lots of factors. That aside, this will currently be equival to send(“eval”, ...).
"excited"[0..4].delete("c")
I especially enjoyed this one. What an exciting way of exiting!
Well done on the syntax highlighting and progressive refactorings, flgr. (Seen on Anarchaia.)