2017-03-04

Destructuring with Ruby

If a method returns an array, you can use destructuring for variable assignment.

def foods
    ['pancake', 'sandwich', 'quesadilla']
end

breakfast, lunch, dinner = foods

breakfast #=> 'pancake'
dinner #=> 'quesadilla'

← Previous Post | Next Post →