Ruby 2.0.0 has been announced and a preview build has been released. This is the first major point release in quite a long time, but what does this mean?
Ruby 2.0.0 is evolutionary, not revolutionary. Despite the major version number increase, there are no real big architectural changes. There are, however, numerous and significant new features. This certainly warrants the bump in the major version, and is another milestone in the maturity of Ruby.
Refinements are an end to the endless monkeypatching. It's common practice to use (or abuse, depending on your views) Ruby's open classes to add methods to base classes. This includes the practice of overriding default methods. But this technique has consequences, your modifications have have unintended consequences anywhere in the program. Ruby's dynamic nature makes it possible to do these things, makes it expressive and powerful, but it also makes it difficult to judge all the interactions that can occur.
Refinements make monkeypatching acceptable. Instead of blindly modifying classes and hoping for the best, a refinement is like a mix-in module that is only applied in certain contexts. Define your refinements in a module with a name of your choosing, use the new refine method to define new methods for classes and enable them in a certain scope using the using method. There's plenty more information on refinements in Feature #4085.
I was hoping for refinements over 2 years ago, glad to see they're finally here!
Ruby has always lacked keyword arguments. You'd think in such an expressive language that keyword arguments would be a key feature (no pun intended), but it's not the case. They can, however, be emulated using a hash and the implicit hash capture. If you didn't know how this worked, you'd have sworn that Ruby already had keyword arguments. But with Ruby 2.0.0, Ruby will have proper keyword arguments.
These look something like hash key-value pairs. Since all keyword arguments need a default value, there's a good parallel here. In this example, the two arguments at the end are keyword arguments, both are optional and can be passed in any order.
def connect(host, port: 80, timeout: 10) # … end connect('google.com') connect('reddit.com', port: 81)
This one might be overlooked by many, but Ruby will now support DTrace. What is DTrace? DTrace is the best tracing and profiling system devised in modern times. It's an extremely powerful tool that can give deep insight into what exactly your Ruby program did. This is better than the Ruby debugger, probably better than Pry, and more useful than letting your program die and sifting through an exception's stack trace.
This is a game-changer for fixing things when they go wrong. It wasn't so long ago that you were completely in the dark, and now that we have DTrace, instead of the primitive candles we used to have we now have a 1 million candlepower light to illuminate anything we need. And to top it all off, DTrace is programmable. You won't be sifting through huge logfiles, you can write DTrace programs to cut out exactly the information you need.
Ruby 2.0.0 on Heroku
It seems like every new Ruby version, the community is a little slow on the uptake. When Ruby 1.9.x came out, it broke virtually every gem out there that needed C compilation. Even though 1.9.x had a much better virtual machine interpreter, people stuck to 1.8.7 simply because it worked and the gems they needed didn't. Not so with Ruby 2.0.0. Right off the bat, Heroku, the largest Ruby cloud host, support Ruby 2.0.0. Right now. Today. Not tomorrow, or when it's released, you can use the preview release on their servers right now. This alone should push through adoption very quickly.