I’d like to “explode” an array in Ruby in order to do a fast variable assignment i.e.
a, b = ['first_var', 'second_var']
Is this possible? I’ve looked through the array docs and can’t find anything that seems to offer this but it seems Rubyish…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This works as you would expect. Note that you can use
*to slurp up extra right hand side elements, whereas extra elements on the left hand side will be set tonil: