From 99e1c31b19547fbe117a77047bb23eff0edafaea Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 30 Jul 2013 15:26:51 +0800 Subject: Updated location, and reduced examples also added array [] access example. --- ruby.html.markdown | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/ruby.html.markdown b/ruby.html.markdown index 7729e0ff..9a59be90 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -4,6 +4,7 @@ filename: learnruby.rb contributors: - ["David Underwood", "http://theflyingdeveloper.com"] - ["Joel Walden", "http://joelwalden.net"] + - ["Luke Holder", "http://twitter.com/lukeholder"] --- ```ruby @@ -30,6 +31,11 @@ You shouldn't either 10 * 2 #=> 20 35 / 5 #=> 7 +## Arithmetic is just syntactic sugar +## for calling a method on an object +1.+(3) #=> 4 +10.* 5 #=> 50 + # Special values are objects nil # Nothing to see here true # truth @@ -121,6 +127,12 @@ array = [1, "hello", false] #=> => [1, "hello", false] array[0] #=> 1 array[12] #=> nil +# Like arithmetic, [var] access +# is just syntactic sugar +# for calling a method [] on an object +array.[] 0 #=> 1 +array.[] 12 #=> nil + # From the end array[-1] #=> 5 @@ -313,21 +325,4 @@ dwight.name #=> "Dwight K. Schrute" # Call the class method Human.say("Hi") #=> "Hi" - -=begin -Arithmetic is just syntactic sugar -for calling a method on an object: -=end -1.+ 1 #=> 2 -1.+(1) #=> 2 - -8.- 1 #=> 7 -8.-(1) #=> 7 - -10.* 2 #=> 20 -10.*(2) #=> 20 - -35./ 5 #=> 7 -35./(5) #=> 7 - ``` -- cgit v1.2.3