Eeck more Ruby parser crapola!

Oh my god! This one pass Ruby parser is really annoying. Here’s todays example that doesn’t compile:

DICTIONARY = create_dictionary
def MyClass.create_dictionary
  ...
end

Yep, you got it, this blows up with a nice error message stating that the variable or method named create_dictionary couldn’t be found. Move the constant definition below, everything is fine. Lame.

4 thoughts on “Eeck more Ruby parser crapola!

  1. Well Ruby is an object scripting language. The emphasis is on scripting. Hence also the lame require/load and lack of decent module namespacing. Matz just needs to take some pointers from guido/joy on this one.

    Like

  2. Lots of scripting languages are read then loaded in line… this is what is happening here, the interpreter doesn’t have reference to the method you are defining until the ‘end’ tag so trying to define something in that space will always blow up… (unless someone wants to have a multi-pass compiler which are a bear.)

    Like

  3. It’s very simple: class and method definition are run-time operations, not compile-time. Ruby does parse the whole file, as you can see if you put some real syntax errors later in the file (like a = + ] ).

    Having class and method definition run-time means you can also redefine methods (and even undefine classes) at run-time. This means that ‘fixing’ your problem would be very hard: If there are two definitions for create_dictionary, which one should Ruby use at that point in the code?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s