I’ve started to work on IRB
as a way to improve my productivity. Following this path I got some nice
stuff in my irbrc.
Recently, I was thinking about how to make irb history closer to the way bash
handles it. I thought there was a need for the following features:
Ignoring duplicated lines on irb exit would be also great.
Some code to solve this problem
This is the code I wrote:
I don’t like the naming much but I never do. Here are some examples of how to
use the code:
I wanted a bash like history and none of the solutions I found had a working
re-execute command. I found some solutions but all of them used eval to
execute code and did not replace the re-executed command in the history. The
h! method I wrote uses irb_context to evaluate the input lines. The issue
with the eval version is easy to explain with an example:
Not a big deal but I really prefer my implementation of the re-execute
command. However, I can’t explain the difference between the two
implementations. I think it may be a scope problem, please let me know if I’m
The last feature I wanted to have in my irb history is the equivalent to this
It means erasing your duplicates commands from your history and I came up with
Not the most beautiful code but it does his job: IRB.conf[:AT_EXIT] is an
array of proc that IRB calls when you exit. Thus, I added a proc that rewrites
irb history without duplicates.