Archive for October, 2009

the underscore variable in Ruby

Thursday, October 8th, 2009

Seems like the underscore variable returns the result of the previous statement, and you can use it in assignment like you do with Erlang to eat up list members you don’t care about.

>> _
=> nil

>> 123
=> 123

>> _
=> 123

>> _, _, a = [1,2,3]
=> [1, 2, 3]

>> a
=> 3

>> _
=> 3