how far down does this thing go?

more Ruby goodness

I continue to be impressed by how deep you can dig into every single Ruby object, class, module and "you name it". There seems to be nothing unreachable in a Ruby program, and just when I think I've found the bottom, another worm hole comes into view. Here's an example based on reading in Programming Ruby, 2nd Edition (the pick axe book) :


    # create the class
    irb(main):018:0> class Shovel
    irb(main):019:1> public
    irb(main):020:1> def dig_deep
    irb(main):021:2> never = 4
    irb(main):022:2> ends = 2
    irb(main):023:2> local_variables
    irb(main):024:2> end
    irb(main):025:1> end

    # call instance method
    irb(main):026:0> shovel = Shovel.new
    => #<Shovel:0x2dd04d0>
    irb(main):027:0> shovel.dig_deep
    => ["never", "ends"]

The output of local_variables unto itself isn't what surprises me. But the way Ruby lets you see anything, at any time... that it was built to allow seemingly unlimited introspection... that's what makes Ruby so much fun.

Posted by Luke on Friday, July 27, 2007