mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-01-17 05:28:37 +01:00
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.
This commit is contained in:
parent
09eadbb895
commit
8c89f3f608
@ -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
|
||||
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user