diff options
author | Luke Holder <lukemh@gmail.com> | 2013-07-30 15:26:51 +0800 |
---|---|---|
committer | Luke Holder <lukemh@gmail.com> | 2013-07-30 15:26:51 +0800 |
commit | 99e1c31b19547fbe117a77047bb23eff0edafaea (patch) | |
tree | 7500229e3e2b051455131552c990e2814e95eb2d | |
parent | 8c89f3f6083c93fa7ca04148a0e7aa07ff0d4545 (diff) |
Updated location, and reduced examples
also added array [] access example.
-rw-r--r-- | ruby.html.markdown | 29 |
1 files 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 - ``` |