A glimpse at the parser

Recently a user by the name of 7stud has been asking questions about Hash on comp.lang.ruby. In some curiosity fueled by his, I was playing around with this:

class Hash
  alias_method :old_get, '[]'

  def [](key)
    puts "#{key} => #{old_get(key)}"
    old_get(key)
  end
end

I was expecting little more than (assuming a = {:b => ‘c’}):

003:0> a[:b]
b => c
"c"

But what I got (besides a whole bunch of irb config values and Wirble related output) included this:

a =>
a =>
[ => #<IRB::SLex::Node:0x13dce34>
: =>
: => #<IRB::SLex::Node:0x13dd514>
b =>
b =>
b =>
] => #<IRB::SLex::Node:0x13dd6cc>=>
] => RubyToken::TkRBRACK

 => #<IRB::SLex::Node:0x13df7b0>

It’s too late on a Sunday to look further, but it’s nice to see how much is right there for the gleaning.

Leave a Comment