Wednesday, September 9, 2009

IRB tricks: assign last statement's return value to a var

irb(main):001:0> 1+2
=> 3
irb(main):002:0> a=_
=> 3
irb(main):003:0> a
=> 3

Underscore assigns the last executed statement's return value to a.

No comments: