diff options
author | Cameron Schermerhorn <Cameron.Schermerhorn@its.ny.gov> | 2015-10-09 13:30:07 -0400 |
---|---|---|
committer | Cameron Schermerhorn <Cameron.Schermerhorn@its.ny.gov> | 2015-10-09 13:30:07 -0400 |
commit | d2010c08604c25b3166977e0cde795732ecde551 (patch) | |
tree | d4d6d72b9364e85decc55770e1f451f479321b67 /ruby.html.markdown | |
parent | bf7d33037f64ea9f80f106a37929e3fdf20bd24d (diff) | |
parent | ea943b61fbee8fb0ba34f88b4d0380400e890f30 (diff) |
Merge remote-tracking branch 'refs/remotes/adambard/master'
Conflicts:
java.html.markdown
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r-- | ruby.html.markdown | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..fe142365 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 @@ -269,6 +275,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 |