This Week in Rails: Getting Ready For Ruby 2.4

You are reading This Week In Rails!

This week’s Rails contributors

The content for this week’s newsletter is sponsored by the 19 individuals who authored them!

Fixnum and Bignum are deprecated in Ruby 2.4

One of the notable changes in the upcoming Ruby 2.4 release is the unification of Fixnum and Bignum into a single Integer class. Following that change, the legacy classes were deprecated recently.

This pull request avoids triggering those deprecation warnings with a feature detection. If you maintain code that references those constants, you might want to adopt this pattern in your projects too!

Remove json gem dependency

Related to the unification of the integer classes: native extensions that references the rb_cFixum and rb_cBignum C constants need to be updated as well.

The popular json gem is one of those native extensions. Fortunately, all modern versions of Ruby bundles the json library. If your are targeting Ruby 1.9 and above, you could simply remove the json gem as a dependency.


Avoid bumping the class serial

Back in May, a regression was reported that Rails 5 invalidated Ruby’s class_serial on each request. This internal counter is used to invalidate the class-level method caches.

The issue was tracked down to the use of instance_exec. While there is hope that this restriction could be relaxed inside Ruby itself, this patch at least temporarily fixes the problem on Rails’ side.

Speed up

Once upon a time, could be quite a bit slower than the stock (allegedly up to 25 times slower). This pull request significantly closes the gap.


Avoid compiling ruby keywords into template locals

Have you tried rendering a partial while injecting local variables called “class” or “module”? It wouldn’t work, and it will give you a pretty bizarre error.

This pull requests avoids the error by skipping over invalid local variable names, while still allowing them to be accessed via local_assigns.

You can read more about this issue, as well as the story behind this pull request in Peter’s blog post.


Remove undocumented Action Cable “faye mode”

Did you know that there was an undocumented “faye mode” for Action Cable?

No? Good. Because it’s now gone!

Wrapping up

That’s it for this week, as usual there were more changes than what we can fit, feel free to check them yourself here!

Until next week!