diff options
| author | Ryan Plant <ryan@ryanplant.net> | 2016-01-26 11:52:06 +1100 |
|---|---|---|
| committer | Ryan Plant <ryan@ryanplant.net> | 2016-01-26 11:52:06 +1100 |
| commit | 0f5c74a79f328aa1b385a2dae3389d48faa47ce5 (patch) | |
| tree | 0d00cbd284946549484bcf269671f3e3927b7982 | |
| parent | 82cb669cd77e0b394be0161ea8c688aa78f955d6 (diff) | |
Add note on destructuring assignment
| -rw-r--r-- | ruby.html.markdown | 9 |
1 files changed, 9 insertions, 0 deletions
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 |
