From 82cb669cd77e0b394be0161ea8c688aa78f955d6 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 26 Jan 2016 11:44:47 +1100 Subject: [PATCH 1/4] Fix typo --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby.html.markdown b/ruby.html.markdown index 3eed2d3c..24dd788a 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -285,7 +285,7 @@ hash.each do |key, value| puts "#{key} is #{value}" end -# If you still need and index you can use "each_with_index" and define an index +# If you still need an index you can use "each_with_index" and define an index # variable array.each_with_index do |element, index| puts "#{element} is number #{index} in the array" From 0f5c74a79f328aa1b385a2dae3389d48faa47ce5 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 26 Jan 2016 11:52:06 +1100 Subject: [PATCH 2/4] Add note on destructuring assignment --- ruby.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From b9c1502cab19360bda496df5a2503a198f7c4f50 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 26 Jan 2016 11:58:46 +1100 Subject: [PATCH 3/4] Add note on method naming conventions --- ruby.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ruby.html.markdown b/ruby.html.markdown index 6743de6b..bdad4d06 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -419,6 +419,19 @@ breakfast, lunch, dinner = foods breakfast # 'pancake' dinner # 'quesadilla' +# By convention, all methods that return booleans end with a question mark +5.even? # false +5.odd? # true + +# And if a method ends with an exclamation mark, it does something destructive +# like mutate the receiver. Many methods have a ! version to make a change, and +# a non-! version to just return a new changed version +company_name = "Dunder Mifflin" +company_name.upcase #=> "DUNDER MIFFLIN" +company_name #=> "Dunder Mifflin" +company_name.upcase! # we're mutating company_name this time! +company_name #=> "DUNDER MIFFLIN" + # Define a class with the class keyword class Human From 236cc1c14c71e561d9ab715079f6974a86fad271 Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Tue, 26 Jan 2016 11:59:08 +1100 Subject: [PATCH 4/4] Fix formatting on comments --- ruby.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby.html.markdown b/ruby.html.markdown index bdad4d06..adf5ce81 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -416,8 +416,8 @@ def foods ['pancake', 'sandwich', 'quesadilla'] end breakfast, lunch, dinner = foods -breakfast # 'pancake' -dinner # 'quesadilla' +breakfast #=> 'pancake' +dinner #=> 'quesadilla' # By convention, all methods that return booleans end with a question mark 5.even? # false