Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [Ruby Forum] irb feature suggestion

Reply
Thread Tools

[Ruby Forum] irb feature suggestion

 
 
Alexey Verkhovsky
Guest
Posts: n/a
 
      09-27-2004
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(<<END)
# ... some YAML here ...
END
and got the right result, then realised I had no way of using it.



 
Reply With Quote
 
 
 
 
Mark Hubbart
Guest
Posts: n/a
 
      09-27-2004

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(<<END)
> # ... 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



 
Reply With Quote
 
 
 
 
Dave Thomas
Guest
Posts: n/a
 
      09-27-2004

On Sep 27, 2004, at 14:13, Alexey Verkhovsky wrote:

> How do you get the value of the last expression entered in irb?


dave[ruby/lib 14:26:14] irb
irb(main):001:0> 1 + 2
=> 3
irb(main):002:0> conf.last_value
=> 3



Cheers

Dave



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
irb require ... where does irb look? what path? anne001 Ruby 1 06-27-2006 12:07 PM
irb question - variable definitions when calling irb from a script problem Nuralanur@aol.com Ruby 1 10-26-2005 09:13 PM
[ANN] irb-history 1.0.0: Persistent, shared Readline history for IRB Sam Stephenson Ruby 1 06-18-2005 08:56 AM
Suggestion for an "imagemap-like" location feature -- methods? KatB ASP .Net 4 01-22-2005 01:46 AM
feature suggestion flexibal Python 3 12-24-2004 11:36 PM



Advertisments