Many useful features like syntax highlighting, multiline editing, display documents, enable auto indent, enable save and load history by default are introduced in IRB with Ruby 2.7.
Let’s take a look at these features in detail.
Before Ruby 2.7, code on the IRB was only black and white.
Ruby 2.7 has introduced syntax highlighting in IRB inspired by pry.gem to source lines, REPL input, and inspect the output of some core-class objects.
Keywords, core-class objects are now colorized as shown in the above image.
Introduce multiline mode by Reline
Before Ruby 2.7, you must have experienced an issue with navigating to previous lines when executing multiple lines of code on IRB.
You probably have pressed up arrow key (↑) multiple times to get to the required line as IRB loads one line at a time.
I had to press up arrow key more than 50 times
to get each line of method definition of
There are ways like
editing the content in other editors and then pasting on IRB.
But it is not convenient when we are
trying out something on IRB.
Ruby 2.7 has enabled multi-line editing which is powered by reline, readline compatible pure Ruby implementation.
With this feature, we can now load the whole method definition with just a single press of up arrow key. We can navigate on any line in the method and edit it just like a text editor.
Show documentation when completion.
RDoc installs all documents to Ruby’s directory by default. It can then be used with ri command to get Ruby documentation.
Before Ruby 2.7, pressing TAB key gives suggestions as follows
Ruby 2.7 has provided a new feature that shows documentation when TAB key is pressed twice.
Documentation will look like,
Enable auto indent
Before Ruby 2.7,
auto indentation is turned off by default in irb.
It can be turned on by adding
With Ruby 2.7,
indentation will be
turned on by default.
It can be turned off by changing
to false in
Save and load history by default
Before Ruby 2.7, IRB disables history by default and does not store any commands that we use.
We can enable history by
adding the following to
This will now save last 1000
With Ruby 2.7, history will be saved and restored by default.
Its refreshing to see so many improvements in the built-in IRB. More improvements are being made in this area for us to look forward to.