In association with heise online

This and that

A few minor but far from inconsequential new features deserve a brief mention before we finish.

  • Module#prepend: Core developer Yusuke Endoh says that Module#prepend may end up being "the most (implicitly) used feature" of Ruby 2.0. It replaces the method_alias_chain in Rails with an unambiguous mechanism that uses modules. At present, modules in a class are used via include and make their methods available. Class methods can't simply overwrite module methods if the module methods are accessible via super, but the opposite is currently not true. This is where the prepend keyword comes into play. If a module is placed at the beginning of a class using the prepend instruction, the modules's methods will overwrite those of the class, if the class methods are accessible via super.

  • RubyGems 2.0: The new version of Ruby comes with RubyGems 2.0, which introduces various improvements to the Ruby package management system. Particularly noteworthy is the support for gemdeps files. These files contain information on which versions of which gems are required for executing an application. Although the functionality isn't yet fully Bundler compliant, it still provides a simple way of using these files. For example, a gem install call from this file can install the required gems.

  • Onigmo is now Ruby's regular expression engine: Onigmo was introduced as a regular expression engine with Ruby 1.9, and in Ruby 2.0 it has become the default choice. Onigmo is a fork of Oniguruma, a RegEx library that follows Perl syntax principles. The current version of Onigmo includes fixes from Ruby 1.9.3 and Perl 5.10+. This engine promises various new features such as conditional evaluations and the use of backreferences. Gabriele Renzi provides a comprehensive summary of Onigmo's features, complete with various examples, on his blog.

Upgrading from Ruby 1.9 to Ruby 2.0

At the moment, the number of incompatibilities is manageable:

  • The default character encoding for Ruby programs has been changed from US-ASCII to UTF-8. Feedback concerning unexpected program behaviour has already been received during the testing of the release candidates.
  • The iconv library (which converts from one character encoding to another) has been removed. The developers had already marked it as "deprecated" with the introduction of M17N ("multilingualisation") in Ruby 1.9. Their recommendation is to "use String#encode, etc instead".
  • ABI breaks: these should normally be fixable by reinstalling an extension.

Conclusion

Upgrading to Ruby 2.0 should be possible without causing any major problems for existing programs, says Yusuke Endoh. The developer points out that ensuring that the new Ruby is almost fully compatible with Ruby 1.9 was a development priority. As Ruby's overall performance has improved in Ruby 2.0, upgrading is worthwhile. The core team said that it would like to see Ruby 1.9.3 replaced as soon as possible.

The only remaining question is: how will the Ruby on Rails web framework handle a new version of Ruby? Unsurprisingly, the new version of Ruby on Rails (4.0), which requires Ruby 1.9.3 or above, recommends the use of Ruby 2.0.


About the authors: Tim Keller works as a senior consultant at innoQ Deutschland GmbH. Christian Albrecht (@coastalchief) works as a principal consultant at innoQ Deutschland GmbH; Ruby and Ruby on Rails are his weapons of choice when implementing web applications.


Print Version | Permalink: http://h-online.com/-1810233
  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit
 


  • July's Community Calendar





The H Open

The H Security

The H Developer

The H Internet Toolkit