From: Mark Hubbart Date: 2004-09-28T04:21:49+09:00 Subject: Re: [Ruby Forum] irb feature suggestion On Sep 27, 2004, at 12:13 PM, Alexey Verkhovsky wrote: > Cross-posted from Ruby Forum: > http://www.ruby-forum.org/bb/viewtopic.php?t=62 > > ---- > > How do you get the value of the last expression entered in irb? > > SML/NJ puts it in the variable 'it', Python uses '_', I think. > So you can do something like this: > Code: >> 6*9 > => it = 54 >> it - 12 > => it = 42 > > Can you do this in Irb? It's very useful for evaluating expressions > interactively, without cluttering up your symbol table (e.g. when > evaluating something piece-by-piece to see how it's working.) > > For example, I just did > Code: > YAML::load(< # ... some YAML here ... > END > and got the right result, then realised I had no way of using it. I distinctly remembered this one from a few months back... In ruby-talk:102888, Nobu Nakada said: > EVAL_HISTORY enables _. > > $ grep HISTORY ~/.irbrc > IRB.conf[:EVAL_HISTORY] = 1000 > IRB.conf[:SAVE_HISTORY] = 100 > > $ irb > irb(main):001:0> 2+2 > => 4 > irb(main):002:0> _ > => 4 > irb(main):003:0> > > -- > Nobu Nakada So, just add those lines to your ~/.irbrc, and that's it. HTH, Mark