The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Cleaned in a Gross Way

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Cleaned in a Gross Way Posted: May 9, 2005 4:57 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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…

 send(Kernel.methods.find_all{|x|x[0]==?e}[-1],
 "re#{q[5...8].downcase}re '111112101110-117114105'.scan(/-|\\d{3}/).
 inject(''){|m,v|v.length>1?m+v.to_i.chr: m+v}");

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.)

Read: Cleaned in a Gross Way

Topic: Ruby Style Previous Topic   Next Topic Topic: Lunch with Rael and Lucas

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use