Slashdot Mirror


Ruby 1.8.0 Released

waieitch writes "A long-waited new version of the scripting language, Ruby 1.8.0 has just been released. You can download from here, and the changelog is available. With many new libraries, say dRuby, ERB, REXML, this version is doubled by 1.6.8 in size."

1 of 97 comments (clear)

  1. Re:Former perl, python, java geek gone to Ruby by xteddy · · Score: 5, Informative

    Why can't I define a method that takes two or more blocks (e.g. if/then/else) with the same syntax I use for methods that take a single block? Why can't I introspect the structure of a block? Why the duality with Proc objects? In short, why aren't blocks first class objects?

    To clarify this first: It's always possible to create multiple Proc objects with Proc.new, lambda or proc and pass them to a method.

    There are two reasons why there are blocks AND Proc objects:

    1. To use a block it's not necessary to create an object and that's good for the performance, e. g. if you have to iterate very often over some collection.
    2. Blocks are used for iterators and control structures, so Matz wanted them to look like those already did.

    It would perhaps be possible to have something like that:

    foo { ... } { ... }
    But there is an ambiguity because the first block could also be a hash constructor. I am not sure if it would be possible to solve that problem by changing the parser. You could limit yourself to use only do ... end with multiple blocks but I thinks that it's better not to have multiple do ... end blocks in one method call.

    BTW: The if/then/else is not a method call and the selectors consist only of a single word in Ruby unlike in Smalltalk. So it would require a big change to the language and the interpreter if blocks should be used there.

    Introspection of blocks is a good idea. Perhaps this will be possible if the new VM for Ruby 2.0, called Rite, is implemented. AFAIK it also should be possible to change code in the parse tree on the fly at arbitrary places then.

    More to the point, in ruby I'd like to be able to change the scope or storage class of an object reference without having to rename it.

    This is clearly a tradeoff. You can choose between having to look up the variables everytime you want to know their scope or between seeing it easily and change every variable if you want to extract a method. I think to choose the latter is a good choice for a language where you don't usually program in a code browser.