Merge pull request #143 from lukeholder/patch-1

Explained syntactic sugar is really just method calls.
This commit is contained in:
Adam Bard 2013-07-31 23:25:15 -07:00
commit 53f0fd4d71

View File

@ -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"
```