Irb idea: return value history

Here’s a made-up irb session I wish I could have:

irb(main):001:0> 17+4
=> 21
irb(main):002:0> ‘hello, fellow’
=> "hello, fellow"
irb(main):003:0> history[1]
=> 21
irb(main):004:0> x = !!
=> 21
irb(main):005:0> x
=> 21
irb(main):005:0> history
[<what should go here? nil?>, 21, “hello, fellow”, 21, 21, 21]

Perhaps something like this functionality already exists? I don’t know. In
any case, it would be wonderful if I could pull back the return values from
previous lines. It would also be nice if I could pull back the last return
value with something shorter than `history.last’.

In fact, history[num]' is maybe not the best way of doing it; too many characters. maybe something like/his’ or even /h'? You would never start a fresh line of Ruby with a slash, so maybe irb could rewrite those for us. Then we could have/!’ for last value returned.

Actually, history is probably misleading, since I’m interested in the return
value, not the input line… so perhaps something like /12' would be translated by irb to$return_values[12]’. So…

/num --> $return_values[num]
// or /! --> $return_values.last
/* --> $return_values.each {|val| puts val.inspect}
# not inspect if flag is set?

So would this help anyone else out, too? I find myself trying something
out, then depending on what it does I might want to do something else with
that value. I end up preceding everything with `a = ’ or something.

Lines which don’t complete an expression could just be considered as
returning `nil’.

(Next step: multi-line editing for multi-line expressions! Then we can
ignore what I just wrote, because every “line” would return an expression.)

Chris

[snip]
/num --> $return_values[num]
// or /! --> $return_values.last
/* --> $return_values.each {|val| puts val.inspect}
# not inspect if flag is set?

···

----- Original Message -----

On second thought, you would also want to be able to use the old return
values in other expressions, and not necessarily always at the beginning of
the line (though I probably do that most frequently). So maybe a shorter
name than `$return_values’ would be best.

irb(main):022:0> RV[12] + RV[21]
=> “hello world”

Maybe a constant would be better? `RV’ for “returned values”? But for the
record, I still like the slash tricks from above (/12, //, /*, others?).

Chris

/num → $return_values[num]
// or /! → $return_values.last
/* → $return_values.each {|val| puts val.inspect}
# not inspect if flag is set?

I’d like something like this too.

So would this help anyone else out, too? I find myself trying something
out, then depending on what it does I might want to do something else with
that value. I end up preceding everything with `a = ’ or something.

Me too. I usually hit the up-arrow key and continuously edit the line.

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Hi –

···

On Sat, 8 Feb 2003, Chris Pine wrote:

In fact, history[num]' is maybe not the best way of doing it; too many characters. maybe something like /his’ or even /h'? You would never start a fresh line of Ruby with a slash, so maybe irb could rewrite those for us. Then we could have /!’ for last value returned.

I start lines with / a lot, when testing regexes.

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Hi,

Here’s a made-up irb session I wish I could have:

Try conf.eval_history.

irb(main):005:0> conf.eval_history=100
=> 100
irb(main):006:0> conf.eval_history
=> 100
irb(main):007:0> __
=> 5 100
6 100
irb(main):008:0> 1+2
=> 3
irb(main):009:0> _
=> 3
irb(main):010:0> __
=> 5 100
6 100
7 …self-history…
8 3
9 3
irb(main):011:0> __[2]
=> nil
irb(main):012:0> a = “abc”
=> “abc”
irb(main):013:0> a.sub(/a/,“z”)
=> “zbc”
irb(main):014:0> __
=> 5 100
6 100
7 …self-history…
8 3
9 3
10 …self-history…
11 nil
12 “abc”
13 “zbc”

···

At Sat, 8 Feb 2003 21:09:30 +0900, Chris Pine wrote:


Nobu Nakada

To David:

Of course! I forgot regexes. D’oh!

To Nobu:

Beautiful! Is there a way to set conf.eval_history automatically every
time?

Chris

Put it in your .irbrc file.

Gavin

···

On Sunday, February 9, 2003, 12:04:39 PM, Chris wrote:

Is there a way to set conf.eval_history automatically every time?