From e3c528bb81a09d715cada5f2d7dac04853ac0ccc Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 15:25:50 -0400 Subject: add modulus operator --- ruby.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..ec7b2f5e 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -39,6 +39,7 @@ You shouldn't either 10 * 2 #=> 20 35 / 5 #=> 7 2**5 #=> 32 +5 % 3 #=> 2 # Arithmetic is just syntactic sugar # for calling a method on an object -- cgit v1.2.3 From f4c13bc6963a79bf419f78a554c5abf3bd7a5bd8 Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 15:26:10 -0400 Subject: array first and last methods --- ruby.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index ec7b2f5e..7fe34336 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -155,6 +155,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] # Arrays can be indexed # From the front array[0] #=> 1 +array.first #=> 1 array[12] #=> nil # Like arithmetic, [var] access @@ -165,6 +166,7 @@ array.[] 12 #=> nil # From the end array[-1] #=> 5 +array.last #=> 5 # With a start index and length array[2, 3] #=> [3, 4, 5] -- cgit v1.2.3 From 3b0bc74c568d88ea30dbca94b8312381d61fe3de Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 15:26:25 -0400 Subject: ruby each with index --- ruby.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 7fe34336..51c4b9d8 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -261,6 +261,12 @@ 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 +# variable +array.each_with_index do |element, index| + pust "#{element} is number #{index} in the array" +end + counter = 1 while counter <= 5 do puts "iteration #{counter}" -- cgit v1.2.3 From 6fce99b0ee62648c40b36751724ab3b74401f7d7 Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 15:40:31 -0400 Subject: Add ghalley as ruby contributor --- ruby.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 51c4b9d8..bd1497ce 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -12,6 +12,7 @@ contributors: - ["Dzianis Dashkevich", "https://github.com/dskecse"] - ["Levi Bostian", "https://github.com/levibostian"] - ["Rahil Momin", "https://github.com/iamrahil"] + - ["Gabriel Halley", https://github.com/ghalley] --- -- cgit v1.2.3 From 7b4d529c5e0dd4b62cf91a90ec72fe40ecca86ec Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Fri, 9 Oct 2015 11:47:13 -0400 Subject: Fix puts typo --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index bd1497ce..88efe322 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -265,7 +265,7 @@ end # If you still need and index you can use "each_with_index" and define an index # variable array.each_with_index do |element, index| - pust "#{element} is number #{index} in the array" + puts "#{element} is number #{index} in the array" end counter = 1 -- cgit v1.2.3