last result in Ruby REPL
Asked Answered
C

1

6

In the Scala REPL if you evaluate something its value is stored in res{N}, as is discussed here: How can I access the last result in Scala REPL?. Is there a similar feature for the ruby REPL, or do the results get lost if you don't capture their value in a variable?

Cognition answered 16/7, 2013 at 17:21 Comment(0)
K
9

You can use the underscore _ in irb to refer to the last returned result:

1 + 5
# => 6

_ + 10
# => 16
Keare answered 16/7, 2013 at 17:25 Comment(2)
Is there some way to get the last returned result when executing a ruby script like this (not in irb)?Substage
No, and there's not really a reason to. You can an assign any expression to a local variable (even _ if you want to, though you probably shouldn't), but it's not implicitly assigned by the vm.Keare

© 2022 - 2024 — McMap. All rights reserved.