[Ruby Forum] irb feature suggestion

Discussion in 'Ruby' started by Alexey Verkhovsky, Sep 27, 2004.

  1. 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.
    Alexey Verkhovsky, Sep 27, 2004
    #1
    1. Advertising

  2. Alexey Verkhovsky

    Mark Hubbart Guest

    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
    Mark Hubbart, Sep 27, 2004
    #2
    1. Advertising

  3. Alexey Verkhovsky

    Dave Thomas Guest

    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
    Dave Thomas, Sep 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KatB
    Replies:
    4
    Views:
    470
  2. VB Programmer

    Need good configurable forum... suggestion?

    VB Programmer, Oct 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    360
    =?Utf-8?B?UGF0Qg==?=
    Oct 14, 2005
  3. flexibal

    feature suggestion

    flexibal, Dec 24, 2004, in forum: Python
    Replies:
    3
    Views:
    260
    John Machin
    Dec 24, 2004
  4. Stewart Midwinter
    Replies:
    4
    Views:
    498
  5. Alexey Verkhovsky

    [Ruby Forum] Forum digest by email

    Alexey Verkhovsky, Sep 22, 2004, in forum: Ruby
    Replies:
    0
    Views:
    400
    Alexey Verkhovsky
    Sep 22, 2004
Loading...

Share This Page