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