Six.new
Ruby 2.4.0
Since Ruby Facets took a Winter break, we missed the joyful release of Ruby 2.4 on December 25th. Aside from the release blog post which listed the marquee features and improvements of this release, I highly recommend Jonan Scheffler's post on the Heroku
blog which goes a LOT more in-depth about some of the changes.
One of the most exciting for me is the introduction of the binding.irb
command. It's a copycat of the binding.pry
command from the Pry gem which allows you to open a breakpoint and stop execution of your Ruby program to inspect the state of code. This is an extremely useful debugging tool that until now required adding a gem to your Gemfile. If you've only ever done debugging with put statements, you really should try this out.
Later in the post, Jonan goes full Ruby Under A Microscope on the way Hashes are actually implemented in Ruby. He shows how Vladimir Makarov's patch for Ruby 2.4 improved the performance of Ruby Hashes by more than 40% on modern CPUs. Jonan also goes wayyyyy too deep for my puny little brain on unified integers — meaning Fixnum and Bignum becoming the new Integer class. Finally he covers the thankfully timid new rounding behavior changes which almost caused a few breaking changes in 2.4.
TruffleRuby
It's truffle season. I don't mean the delicious subterranean fungus. I mean TruffleRuby.
That would be the new name of the project once known as JRuby + Truffle. It was quite a mouthful so the new name was probably wise. More importantly, the project's maintainer — Chris Seaton — announced a few days ago that TruffleRuby now passes 100% of the Ruby language specs. This is quite an accomplishment for such a relatively new alternative Ruby implementation.
Such implementations — especially the ones that aren't written in C — often struggle with the native C extensions commonly found in Ruby gems like nokogiri. TruffleRuby is supposed to sidestep this issue by using an LLVM bitecode interpreter which essentially can translate the C code into something the Java Virtual Machine can understand.
But the most impressive feature of this project is its performance goal. The optcarrot benchmark which is being used as the measuring stick for the Ruby 3x3 project — which aims to make Ruby 3.0 3 times faster than Ruby 2.0, runs 9 times faster on TruffleRuby.
Granted, there are still a lot of things left unfinished in the implementation. For example, the boot time for a simple hello world program is about 10 times slower than CRuby right now, but it should be possible to bring it to the same speed.
TruffleRuby isn't merely an academic research project either. It now passes 100% of Rails' Active Support and Active Model tests, as well as 98% of Action Pack tests. Active Record, Action View and Railties are nearly there.
It looks like there are a lot of interesting performance improvements for Ruby on the horizon. http://lists.ruby-lang.org/pipermail/jruby/2017-January/000511.html
Bundler 1.14
Bundler 1.14 just came out with a loooot of bug fixes from the ever prolific Samuel Giddins. On the performance side, running require "bundler"
should be five times faster, and gems can now install in parallel when running on rubygems 2.0 and greater.
Feature-wise there are new improvements to the bundle doctor command — which checks the operating system dependencies for the gems listed in the Gemfile to ensure they're present, for example for the pg gem that would be a postgres installation. Now bundle doctor will first run bundle check to ensure that all the gems in the Gemfile have been installed on the local machine.
If you're concerned about security, Bundler finally validates gem checksums when installing them to compare them with rubygems.org records which could prevent man-in-the-middle attacks.
There are a lot more subtle improvements and new features in this version so I highly recommend scanning thorough changelog for this release and running gem update bundler to get the new shiny.
Kaminari 1.0.0
I remember when I was mostly a front-end developer and I knew very little about Ruby. Most of what I was exposed to at the time where these cool HTML-focused gems like formtastic, simple_form, will_paginate, and kaminari.
Well, version 1.0 of Kaminari is now out with some major changes. First, no more Ruby 1.9.3 — which is unsupported anyway. JRuby 1.7, Rails 3.2 and 4.0 are also no longer supported.
Separate gems for specific platforms and ORMs have been introduced so you can add kaminari-sinatra and or kaminari-mongoid if you don't use it with Rails or Active Record.
There's also a new without_count method to avoid triggering a potentially very slow count query on large tables. Instead Kaminari will infer the previous and next pages based on the current one. Sadly, it will therefore be impossible to list the total number of pages. But it's a nice solution when performance is crucial.
Finally there's now an option to display query parameters even on the first page so that other query parameter filters can be persisted if the page is refreshed.
Castaway
Jamis Buck made a new delightful little thing out of Ruby with Castaway, an elegant domain-specific language that lets you write code to generate a well-produced screencast or presentation.
Castaway lets you define soundtrack blocks so you can fade music in and out, and even duck the soundtrack when a voice track is present.
You can define scenes that enter and leave with a dissolve transition set to a specific timing, or define background mattes in any color with superimposed text or still images.
You can also use still images as pointers to highlight specific parts of the screen during the video and all visual elements are defined as percentages of the screen so the output can be resolution independent.
Jamis already made a great demonstration of Castaway in a YouTube video so I will put a link to that in the shownotes for you to watch.
It's incredibly refreshing to see people like Jamis have fun with Ruby and make something that actually helps others create and share knowledge. So, thank you Jamis.
Ruby's Gems: swot
This episode is already a bit longer than usual since we had so much to catch up on but I'd like to introduce a small new segment in which I'll talk about something that isn't quite newsworthy but worth your attention nonetheless. I named the segment Ruby's gems because I may talk about not-so-well-known Ruby features or simply really cool Ruby gems that don't necessarily have a new version but that you should check out regardless.
Recently the Code School support team mentioned they were receiving a lot of requests from students around the world who were trying to register through a student discount form but couldn't get past the naive validation for a .edu email address.
I was about to try to find some sort of repository of academic email domains when I happened upon the swot gem from Lee Reilly. First, it taught me that .edu domains aren't necessarily academic because prior to 2001, anyone could register one. Second, I was happily surprised by its extremely simple interface. You call Swot::is_academic?
, pass it an email string and it will tell you whether it thinks that email belongs to a student or an academic. You can also run the check with a domain name with or without a protocol.
Cooler even, the gem can function as a reverse search engine from either an email or a domain to return the name of the school associated with them. So after you give them a discount, you could even welcome students from l'Université Sorbonne-Nouvelle (Paris III) like me and dazzle them with your magic computering.