by Joe Leo III [Twitter](http://twitter.com/jleo3) [GitHub](http://github.com/jleo3) [LinkedIn](http://linkedin.com/in/jleo3)
This Christmas, Ruby creator Yukihiro Matsumoto and his development team are releasing
Ruby 2.5, the latest version of Ruby. The release schedule has become a tradition and Rubyists around the world look forward to a brand new version of Ruby to play with on Christmas day. As the Founder of [Def Method](http://www.defmethod.com) and co-author of [The Well-Grounded Rubyist](https://www.manning.com/books/the-well-grounded-rubyist-third-edition?a_aid=defmethod&a_bid=b2a9cb7e), I actively track what features are being updated or added and am always excited to “unwrap” the latest Ruby release!
Below are the top three features you’ll want to know about when you unwrap Ruby 2.5 this Christmas.
1. Bundler, bundled!
Whenever I install a new version of Ruby the very next thing I do is install the bundler gem:
=> gem install bundler
Bundler is key to both installing, organizing, and updating gems. Rubyists use it all the time, but until now the bundler library has been an external gem. This means we had to install a gem to manage our gems!
Beginning with Ruby 2.5, bundler is now a part of Ruby’s core library. You’ll be able to bundle install to your heart’s content as soon as you install Ruby.
This isn’t the first time Ruby has incorporated a gem into its standard library. These days, popular gems like rake, minitest, and did_you_mean are all packaged together in the standard Ruby installation.
2. Object#yield_self
Ruby continues to embrace functional programming principles with this new method for the Object class. yield_self is similar to the way apply is used in other functional programming languages and a close cousin of the tap method. Ben Lewis has a great description of Object#tap, and yield_self has even more to offer. The method receives a block, yields itself, and returns the value of the block:
2.yield_self { |x| x + 5}
=> 7
yield_self promotes method chaining over nested functions. Because each call to yield_self returns the value of the block, it can be called repeatedly:
2.yield_self { |x| x + 5 }.
yield_self { |x| x * 2 }.
yield_self { |x| x - 1 }
=> 13
or easily placed within an existing function:
name = “Joe Leo”
tokens = name.split(“ “)
attrs = { first: tokens[0], last: name.yield_self { |n| tokens.size == 2 ? tokens[1] : tokens[2] } }
=> {:first=>”Joe”, :last=>”Leo”}
In addition to method chaining, Ruby gives you the power to write side-effect free code, build recursive functions, and employ lazy evaluation. These are all foundations of functional programming. yield_self can be used to further your exploration of FP, but it can also be useful in many other contexts. We take a functional programming deep dive in the advanced chapters of The Well-Grounded Rubyist.
3. IRB Power-ups
For years now, I’ve been largely ignoring Interactive Ruby (IRB), the built-in REPL for Ruby, in favor of pry. Pry is a gem that can do everything IRB can do, plus a little extra in terms of debugging. (John Backus has much more to say about Pry.) Ruby began adding its own debugging tools to IRB in version 2.4. With the release of version 2.5 Ruby’s debugging capabilities are finally up to snuff.
Since Ruby is a dynamic language we can’t rely on a compiler for debugging. Instead, debugging works by inserting a “binding” into the part of the code base you’d like to analyze and then running your program through that binding. Once the binding is hit, the program pauses and the output is shown to you.
Before Ruby 2.5, the IRB library needed to be required in order to invoke the binding:
require ‘irb’ #no longer needed in Ruby 2.5!
def i_need_a_debugger
x = 5
binding.irb
x -= 3
x
end
i_need_a_debugger
Now the require statement is unnecessary. In addition, the debugger gives a few lines of source code before and after your binding so that when the program pauses you have some context to do your debugging. In versions 2.4 and earlier, the only thing to appear on your terminal would be the prompt:
=>
That wasn’t very helpful! Now you’ll have enough source code to get your bearings:
From: c.rb @ line 3 :
1: def i_need_a_debugger
2: x = 5
=> 3: binding.irb
4: x -= 3
5: x
6: end
7: i_need_a_debugger
As is typical, the latest Ruby release has something for everyone. Check out the Ruby core team’s latest announcement for even more great features and fixes in Ruby 2.5. What are your top 3 features of Ruby 2.5? Shout them out on [Twitter](http://twitter.com/jleo3) and we’ll discuss! In the meantime, Happy Holidays!
meanwhile i’m still waiting for 2.4 support on AWS elasticbeanstalk
Didn’t they can the `bundler` inclusion just before shipping?
So rvm list known doesn’t list 2.5 yet, correct? (Ubuntu) Just making sure I’m doing this right.
FYI: I collect [Ruby 2.5 News Bytes](https://planetruby.github.io/advent2017/ruby25) at the Ruby Advent Calendar 2017. For the record so far:
– Standard Gems 2.5.0 – Default Gems, Bundled Gems / by Jan Lelis, Idiosyncratic Ruby
– 10 New Features in Ruby 2.5 / by Junichi Ito, Ruby programmer @ SonicGarden.jp
– 10 More New Features in Ruby 2.5 / by Tom Lord, Software Developer from London
– Performance Improvements in Ruby 2.5 / by Jesus Castello, Ruby Guides
– yield_self in Ruby 2.5 / by Michał Łomnicki
– Improved stacktrace display in Ruby 2.5 / by Michał Łomnicki
– Ruby 2.5 Series / by Amit Choudhary, Mohit Natoo et al @ BigBinary
– What’s new in Ruby 2.5 / by Nimmy Vipin, Red Panthers
– Ruby 2.5 is out – Let’s benchmark / by Thomas Leitner, HexaPDF
– Changes in Ruby 2.5 / by Kir Shatrov, Production Engineer @ Shopify
– What’s New in Ruby 2.5? / by Nithin Bekal, Programmer from Ottawa @ Shopify
– New Features in Ruby 2.5 / by Rodrigo Ponce de León, Ruby developer @ WyeWorks
Seems like, 2.4.3 will be finalized in the family of 2.4…