开发者

Ruby Equivalent of Python "_"

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜