开发者

Ruby Equivalent of Python "_"

开发者 https://www.devze.com 2023-02-07 03:32 出处:网络
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?

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'


_ isn't working?

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


In IRB you can use _ as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消