Ruby 2.0 Reaches Feature Freeze: What Will Change?

Yes, you read right: Ruby 2.0 is in feature freeze! This doesn’t mean it will be released in the next month. But it introduces us the most important changes that will come with version 2.0.

The timing is actually pretty impressive, since this feature freeze was announcement by Yusuke Endoh one year ago! Ruby seems to be on track (pun totally intended)! Want more details? Read on!

The Release Plan

Right now, there are two important milestones left: Code freeze and release. Code freeze is planned at the end of the year. So all the bugs should be more or less ironed out by then.

And then, on February 02, 2013, 20 years after Ruby became part of this world, Ruby 2.0 should be released!

The New Features

There isn’t yet an official list out with all the new features, but the source code, commit history and discussions are open to the public, so it is no secret!

This isn’t a big release as the change from 1.9 to 2.0 would suggest, there are only a handful of new features:

Refinements

Refinements are one of the more interesting changes that could actually change the way Ruby code is written. It allows you to monkey patch a class, but only where you want to, and not in the global scope.

Monkey patching could actually become an accepted thing to do!

Some code? Sure:

Here we define a module that contains a refinement ( refine) for String. Because length should always be 42 (for whatever reason…). Let’s define a class that could use it:

But that is wrong! And that’s right. No, wait, I mean, the answer is wrong, but the rest is right. That’s because we didn’t use the refinement yet, we just defined it.

Let’s use it then:

If we ask for TheAnswerToLifeTheUniverseAndEverything.answer("I want the answer to everything!!! NOOOOOW") it will tell us 42. Exactly what we want. But the behavior of String#length outside of our class hasn’t changed. At all! Only when we use it inside class that is using this refinement is the behavior changed.

Which could be really handy!

Named Arguments

Another one that we might end seeing a lot is named arguments. Named arguments could replace the options hash that is so prevalent in todays Ruby code. Use def namedParameters?(yes: true, no: false) [...] end.

Then there are some internal changes and some speed improvements for MRI. Nothing exciting, but definitely good changes.

Will It Break Stuff?

Most likely? No. The most likely candidate to break stuff? respond_to?.

The behavior of respond_to? in regards to protected methods has changed. By default, in 2.0, it doesn’t search for private or protected methods, in Ruby 1.9 it only excludes private methods. The amazing Tenderlove has a great writeup about this.

Apart from that, it seems like there is nothing else that will break with Ruby 2.0, so the upgrade should be easier then going from 1.8 to 1.9. Even though the roadmap is actually pretty big!

Yay! Exciting Stuff!

I’m looking forward to Ruby 2.0. I’m especially interested in what kind of clever hacks people will come up with now that we have refinements.

What are you looking forward to? What is still missing in your opinion?

If you liked this post, you should consider hiring me freelance, part-time or full-time!

Does Rails Still Deserve To Be The Default Web Framework In Ruby?

To answer the question directly (aka a TLDR here for the impatient): I don't know. Read on! (HA! Tricked you there!) Let's take a dive through some Ruby web frameworks. There is one or two around, even if we don't count Rails. I promise! But … [Continue reading]

Why Microsoft, Why? (aka Introducing TypeScript)

Interesting. Microsoft recently released their own version of JavaScript, TypeScript! Now, some people might want to mock Microsoft for that. Maybe they just couldn't make Visual Studio play nice with JavaScript, so they made TypeScript. Oh wait! I … [Continue reading]

Is The Time of The Big Languages Coming To An End?

Go, Rust, Erlang, R, Closure and what all the new(er) languages around the block are all called. But one thing is certain: They are all niche languages. Why is that? Why don't we have another C or Java? One language to rule them all? If you have … [Continue reading]

Are Your Abusing Constructors, Too?

Ah, constructors. The little, forgotten, and often abused thing. No one really thinks about it for long, no one really knows what it does. Everyone tends to ignore it until they think they need it and throws things into it with no care whatsoever. … [Continue reading]