4

In Python, you can use the _ field to grab the last computed value. That's really useful in IDLE. Does Ruby have an equivalent for IRB?

An example from Python:

>>> 2 + 2
4
>>> _
4
>>> "Me " + "You"
'Me You'
>>> _
'Me You'
Mike
  • 19,267
  • 11
  • 56
  • 72

2 Answers2

11

_ isn't working?

host:~ user$ irb
irb(main):001:0> s = "test"
=> "test"
irb(main):002:0> puts _
test
=> nil
yan
  • 20,644
  • 3
  • 38
  • 48
5

In IRB you can use _ as well.

sepp2k
  • 363,768
  • 54
  • 674
  • 675