Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT: The person who posted the original obfuscated example gave <a href="https://stackoverflow.com/questions/715951/if-this-code-is-not-a-joke-how-on-earth-does-it-work/716110#716110">the actual source code</a> in his answer. He also posted a <a href="https://stackoverflow.com/questions/715951/if-this-code-is-not-a-joke-how-on-earth-does-it-work/716139#716139">corrected version of the obfuscated code</a>, because as I noted, some of it didn't make sense even when you removed the funky syntax.</strong></p> <p>That is some nicely obfuscated code. As with most obfuscated code, it's mostly a lot of ternary operators and a stubborn refusal to put in whitespace where a normal person would. Here is basically the same thing written more normally: </p> <pre><code>class Tree def initialize(*d) @d, = d # the comma is for multiple return values, # but since there's nothing after it, # all but the first are discarded. end def to_s @l || @r ? ",&gt;" : @d end def total total = @d.is_a?(Numeric) ? @d : 0 total += @l.total if @l total += @r.total if @r end def insert(arg) if @d if @l @l.insert(arg) else @l = Tree.new(arg) end else @d = arg end end end </code></pre> <p>The insert method is not syntactically valid (it's missing a method name at one part), but that's essentially what it does as far as I can tell. The obfuscation in that method is pretty thick:</p> <ol> <li><p>Instead of just doing <code>@l = whatever</code>, it uses <code>instance_variable_get()</code> and <code>instance_variable_set()</code>. Even worse, it aliases <code>instance_variable_get()</code> to just be <code>g()</code>.</p></li> <li><p>It wraps most of the functionality in a lambda function, to which it passes the name of the <code>@l</code>. Then it calls this function with the lesser-known syntax of <code>func[arg1, arg2]</code>, which is equivalent to <code>func.call(arg1, arg2)</code>.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload