summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Bard <github@adambard.com>2013-07-31 23:25:15 -0700
committerAdam Bard <github@adambard.com>2013-07-31 23:25:15 -0700
commit53f0fd4d713111ea3e09f03ed97374c8e4b1c48f (patch)
tree12558cd711446f4d4e70d756bda5e00914ae76c1
parentccf11aab5feba6411abf7767e36dc9895ebd0e0b (diff)
parentdf90e4957246c422c00b07f788d825d327304d11 (diff)
Merge pull request #143 from lukeholder/patch-1
Explained syntactic sugar is really just method calls.
-rw-r--r--ruby.html.markdown13
1 files changed, 13 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 38d060a3..a3bcbbd5 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
@@ -312,4 +324,5 @@ dwight.name #=> "Dwight K. Schrute"
# Call the class method
Human.say("Hi") #=> "Hi"
+
```