From d25c10969d2f21c2dde1c89b491f4a7ef15476c4 Mon Sep 17 00:00:00 2001 From: Ariel Date: Mon, 10 Mar 2014 17:05:49 -0400 Subject: [PATCH 1/2] Added some example code and resources. --- ruby.html.markdown | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ruby.html.markdown b/ruby.html.markdown index a4c74a4f..0a28a000 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -8,6 +8,8 @@ contributors: - ["Tristan Hume", "http://thume.ca/"] - ["Nick LaMuro", "https://github.com/NickLaMuro"] - ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"] + - ["Ariel Krakowski", "http://www.learneroo.com"] + --- ```ruby @@ -33,6 +35,7 @@ You shouldn't either 8 - 1 #=> 7 10 * 2 #=> 20 35 / 5 #=> 7 +2 ** 5 #=> 32 # Arithmetic is just syntactic sugar # for calling a method on an object @@ -79,6 +82,10 @@ placeholder = "use string interpolation" "I can #{placeholder} when using double quoted strings" #=> "I can use string interpolation when using double quoted strings" +#Combine strings but not with numbers +"hello " + "world" #=> "hello world" +"hello " + 3 #=> TypeError: can't convert Fixnum into String +"hello " +3.to_s #=> "hello 3" # print to the output puts "I'm printing!" @@ -247,6 +254,22 @@ else puts "Alternative grading system, eh?" end +#=> "Better luck next time" + +# cases can also use ranges +grade = 82 +case grade + when 90..100 + puts "Hooray!" + when 80...90 + puts "OK job" + else + puts "You failed!" +end + +#=> "OK job" + + # Functions def double(x) @@ -474,3 +497,12 @@ Something.qux # => NoMethodError: undefined method `qux' Something.new.bar # => NoMethodError: undefined method `bar' Something.new.qux # => 'qux' ``` + +## Additional resources + +- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges. +- [Official Documentation](http://www.ruby-doc.org/core-2.1.1/) +- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/) +- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online. + + From 933cf6f10d3e894edef4efe1c0d2a4e7aafd3192 Mon Sep 17 00:00:00 2001 From: Ariel Date: Mon, 10 Mar 2014 18:06:44 -0400 Subject: [PATCH 2/2] fixed space --- ruby.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby.html.markdown b/ruby.html.markdown index 0a28a000..962853a2 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -82,10 +82,10 @@ placeholder = "use string interpolation" "I can #{placeholder} when using double quoted strings" #=> "I can use string interpolation when using double quoted strings" -#Combine strings but not with numbers +# Combine strings, but not with numbers "hello " + "world" #=> "hello world" "hello " + 3 #=> TypeError: can't convert Fixnum into String -"hello " +3.to_s #=> "hello 3" +"hello " + 3.to_s #=> "hello 3" # print to the output puts "I'm printing!"