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