From 8c89f3f6083c93fa7ca04148a0e7aa07ff0d4545 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Mon, 29 Jul 2013 16:30:51 +0800 Subject: [PATCH] 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. --- ruby.html.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 + ```