From f165e721cedf80edf560304b7d83b0687045f8b1 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 20:55:51 -0400 Subject: Update ruby.html.markdown --- ruby.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..3e85a038 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -106,8 +106,14 @@ placeholder = 'use string interpolation' 'hello ' + 3 #=> TypeError: can't convert Fixnum into String 'hello ' + 3.to_s #=> "hello 3" -# print to the output +# print to the output with a newline at the end puts "I'm printing!" +#=> I'm printing! +#=> nil + +# print to the output without a newline +print "I'm printing!" +#=> I'm printing! => nill # Variables x = 25 #=> 25 -- cgit v1.2.3 From d73584cc9a7eefbcede32d64fa0fc6177e1640bf Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 21:06:44 -0400 Subject: Add information about mapping arrays --- ruby.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..cf6bf2ce 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -269,6 +269,19 @@ end #=> iteration 4 #=> iteration 5 +# There are a bunch of other helpful looping functions in Ruby, +# for example "map", "reduce", "inject", the list goes on. Map, +# for instance, takes the array it's looping over, does something +# to it as defined in your block, and returns an entirely new array. +array = [1,2,3,4,5] +doubled = array.map do |element| + element * 2 +end +puts doubled +#=> [2,4,6,8,10] +puts array +#=> [1,2,3,4,5] + grade = 'B' case grade -- cgit v1.2.3 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 From b4535eaae356e7c0977c29bbb25464d9e5034e6f Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 14 Oct 2015 09:45:13 -0500 Subject: Fix header to hopefully bring back ruby to the site. --- ruby.html.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index c10255d8..0e798706 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -12,8 +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] - + - ["Gabriel Halley", https://github.com/ghalley"] --- ```ruby -- cgit v1.2.3