summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'ruby.html.markdown')
-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"
+
```