Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 172183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:07:14+00:00 2026-05-11T13:07:14+00:00

class Tree def initialize*d;@d,=d;end def to_s;@l||@r?,>:@d;end def total;(@d.is_a?(Numeric)?@d:0)+(@l?@l.total: 0)+(@r?@r.total: 0);end def insert d alias

  • 0
class Tree   def initialize*d;@d,=d;end   def to_s;@l||@r?',>':@d;end   def total;(@d.is_a?(Numeric)?@d:0)+(@l?@l.total: 0)+(@r?@r.total: 0);end   def insert d     alias g instance_variable_get     p=lambda{|s,o|d.to_s.send(o,@d.to_s)&&       (g(s).nil??instance_variable_set(s,Tree.new(d)):g(s).insert(d))}     @d?p[:@l,:]:@d=d   end end 

Would anyone like to take a stab at explaining what this does? It appeared as an answer in a question I asked about code that is too clever. But it’s too clever for me to tell whether it’s simply a joke. If it’s not, I’d be interested to know how it works, should anyone care to explain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:07:14+00:00Added an answer on May 11, 2026 at 1:07 pm

    EDIT: The person who posted the original obfuscated example gave the actual source code in his answer. He also posted a corrected version of the obfuscated code, because as I noted, some of it didn’t make sense even when you removed the funky syntax.

    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:

    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 ? ',>' : @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 

    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:

    1. Instead of just doing @l = whatever, it uses instance_variable_get() and instance_variable_set(). Even worse, it aliases instance_variable_get() to just be g().

    2. It wraps most of the functionality in a lambda function, to which it passes the name of the @l. Then it calls this function with the lesser-known syntax of func[arg1, arg2], which is equivalent to func.call(arg1, arg2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Solved it. I was using the wrong bType and using… May 11, 2026 at 6:41 pm
  • Editorial Team
    Editorial Team added an answer If the trigger logic is complex enough, sometimes I find… May 11, 2026 at 6:41 pm
  • Editorial Team
    Editorial Team added an answer When you add the stored proc to the sub-report CR… May 11, 2026 at 6:41 pm

Related Questions

I am currently using the directory walker from Here import os class DirectoryWalker: #
I have a class that acts as an item in a tree: class CItem(
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.