Ruby Equivalent to Python "_"

In Python, you can use a field _to capture the last calculated value. This is really useful in IDLE. Does Ruby have an IRB equivalent?

An example from Python:

>>> 2 + 2
4
>>> _
4
>>> "Me " + "You"
'Me You'
>>> _
'Me You'
+3
source share
2 answers

_ does not work?

host:~ user$ irb
irb(main):001:0> s = "test"
=> "test"
irb(main):002:0> puts _
test
=> nil
+11
source

In IRB you can also use _.

+4
source

Source: https://habr.com/ru/post/1788615/


All Articles