Astute readers will recall that during RubyConf last year, I posted about a little irb hack I’d written that allowed for shell-style history viewing and replay. There was a problem with it, however… replayed lines that made assignments didn’t work. So if you tried to replay

1
2
3
4
>> b = 5
=> 5
>> b + 10
=> 15

... you’d get …

NameError: undefined local variable or method `b' for main:Object
        from (irb):1

... which sucks. This has now been fixed! Witness:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>> b = 5
=> 5
>> b + 10
=> 15
>>  exit

superx ~...personal/toys/irbhistory > irb
>> h
[0937] b = 5
[0938] b + 10
[0939] h
=> nil
>> h! 937,938
=> 15

So that’s pretty cool, yeah? You can get the updated code here. It’s also in subversion, here.

Thanks to Giles Bowkett for pointing out a mis-feature that resulted in all evals returning nil, when you’d probably want them to return in the usual way. This is fixed now :)

Sorry, comments are closed for this article.