summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorLuke Holder <lukemh@gmail.com>2013-07-29 16:30:51 +0800
committerLuke Holder <lukemh@gmail.com>2013-07-29 16:30:51 +0800
commit8c89f3f6083c93fa7ca04148a0e7aa07ff0d4545 (patch)
tree27d253248031782b55895e904295db1d5011d593 /ruby.html.markdown
parent09eadbb8951c3404c893e669ae2c4c5e6ad947cb (diff)
Explained syntactic sugar is really just method calls.
Objects in ruby receive a message via the . (dot) notation. The arithmetic operators are just syntactic sugar of the . message notation.
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r--ruby.html.markdown18
1 files changed, 18 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 38d060a3..7729e0ff 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -312,4 +312,22 @@ 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
+
```