From 0f5c74a79f328aa1b385a2dae3389d48faa47ce5 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 26 Jan 2016 11:52:06 +1100 Subject: Add note on destructuring assignment --- ruby.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 24dd788a..6743de6b 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -411,6 +411,15 @@ def guests(*array) array.each { |guest| puts guest } end +# If a method returns an array, you can use destructuring assignment +def foods + ['pancake', 'sandwich', 'quesadilla'] +end +breakfast, lunch, dinner = foods +breakfast # 'pancake' +dinner # 'quesadilla' + + # Define a class with the class keyword class Human -- cgit v1.2.3