Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Ruby 2.0 Implementation Work Begins: What is Ruby 2.0 and What’s New?

By Peter Cooper / October 20, 2011

Yesterday, Matz made a commit to the MRI Ruby repository bumping the trunk version from 1.9.4 to 2.0.0, marking the start of the work of implementing the long-discussed ideas for Ruby 2.0.

What is Ruby 2.0?

Ruby 2.0 is the next major version release of MRI Ruby, the de facto official Ruby implementation.

Ruby 1.9.3 is due out any time soon and Ruby 1.9.4 is under active development (it has moved to a separate branch now that trunk is 2.0.0). We recently learned that Ruby 2.0 would then follow Ruby 1.9.4.

Will Ruby 2.0 be a huge leap forward?

No. While 2.0 will include a number of syntax changes, new features and general improvements, mentioned below, it is anticipated to remain backward compatible with code written for 1.9.3 and Matz has stated that the changes are less significant than those made in the 1.8 to 1.9 jump.

The version number goes up to 2.0 but the changes are rather small. Smaller than the ones we made in 1.9.

Matz

The discussion surrounding Ruby 2.0's feature set spans back several years (mostly on the ruby-talk and ruby-core mailing lists) and 2.0 was initially expected to introduce significant syntax changes and not be backwards compatible. Things have changed with Ruby 1.9 moving into production (it was originally a development only version) and 2.0 being an evolution rather than a revolution.

What will (probably) be new in Ruby 2.0?

Ruby 2.0 is still not well defined. At the moment, ideas and features are being actively suggested and discussed, but a number have been tipped to make it into Ruby 2.0 at this early stage:

Keyword Arguments

In Ruby 2.0: What We Want to Accomplish in the Near Future (recorded in 2010), Matz showed off an example where 1.step(20, 2) could become 1.step(by: 2, to: 20) with the method definition of def step(by: step, to: limit).

An implementation of keyword arguments by Yusuke Endoh actually triggered the discussion to move trunk to 2.0.0 so this is actively being discussed and implemented.

Bytecode export/import

Ruby 1.9 runs on the YARV virtual machine and so will Ruby 2.0, but Ruby 2.0 is expected to make it simple to save pre-compiled Ruby scripts to bytecode representations and to then run these directly. Running pre-compiled bytecode will skip the parsing stage of the standard interpretation process. If you use Rubinius or JRuby you may be familiar with this concept.

Refinements

"Refinements" are a construction to make monkey patching safer. Essentially you could "refine" a global class within the context of a specific module so that the monkey patches would only apply in a certain context. Yehuda Katz wrote an excellent writeup about refinements last year.

Refinements are.. controversial. The performance hit they'd introduce has recently made them less likely to arrive in Ruby 2.0 but I don't believe they're entirely off the table yet. Some form of namespacing of class modifications will probably eventually make it in, however. Another implementation has been called 'traits' and is shown off in the Matz video (linked above).

Standard libraries becoming gems

On Twitter today, Aaron 'tenderlove' Patterson of the Ruby core team said that the Ruby standard library would be 'moved to gems' in Ruby 2.0 although many of these would still be included with the implementation (rather than being an optional extra download).

And more..

As I said before, things are a bit up in the air, but the ideas surrounding Ruby 2.0 should begin to settle over the next year.

A couple of weeks ago, Koichi Sasada posted the results of a Ruby 2.0 feature questionnaire to the ruby-core mailing list and encouraged people to extend it. It's not a list of features that will make it into Ruby 2.0, but an attempt to see what people would like.

Koichi's initial list was:

  • Cleanup syntax
  • Bytecode export
  • Symbol GC
  • Remove Proc binding
  • Macros
  • Getting parse tree
  • Getting source code
  • Cross thread Fiber migration
  • Standard Gem
  • Review all standard libraries
  • Remove obsolete one standard libraries
  • Improve Proc#curry
  • Non-blocking I/O
  • Dtrace
  • GC API (replaceable GC)

As Ruby 2.0 development continues, I'm going to regularly summarize what's going on and show off new features here on Ruby Inside, so keep your eyes peeled :-)

[ad]Gauges is a real time traffic analytics system so you can analyze all your traffic in seconds. Collect and analyze your web traffic for all your sites in real-time using their fast, reliable, hosted system and see overview data for all your sites on a single page. Click here to learn more.

Comments

  1. ano says:

    It's step(limit, step), isn't it? Thus 1.step(20, 2), not 1.step(2, 20).
    Your syntax feels so much more natural though

  2. Guoliang Cao says:

    Great!

    I love ruby 1.8 and 1.9. Backward compatibility is very good and won't diminish the momentum Ruby has gained. Good little things add up too.

  3. Alexey Petrushin says:

    I miss multiple inheritance.

  4. Torrance says:

    Is there any word on performance improvements wrt the YARV virtual machine? Improvements in its garbage collection? etc.?

  5. Peter Cooper says:

    @ano: You're right. I've fixed it :-) Thanks!

  6. Myron Marston says:

    Is module prepending (which would remove the need to ever do alias_method_chain) still a possibility?

  7. Alex Ramirez says:

    *Yawn*

    They should make Rubinius the default VM for 2.0.

    I'm so fed up with YARV segfaulting all the time, I guess I'm going to move to Perl or Python.

  8. dude says:

    @Alexey, Good one. I laughed.

  9. Tobias says:

    I don't feel like Ruby needs many more features; I'd rather see more focus on performance improvements.

  10. Pingback: Ruby 2.0: Planos do criador | SWX Softwares - Desenvolvimento e Design Web

  11. Pingback: The Ruby Standard Library To Be Converted to Gems for Ruby 2.0?

Other Posts to Enjoy

Twitter Mentions