summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorChenbo Li <lichenbo1949@gmail.com>2013-08-02 23:44:26 +0800
committerChenbo Li <lichenbo1949@gmail.com>2013-08-02 23:44:26 +0800
commit90fa867a66323c9936b9b6f833f1c6b9eb7a16ad (patch)
treed236da21d945b9d6f9370b2d770aad19d59280ca /ruby.html.markdown
parent1a52aefcba5c31bb05b58290380509d6da81045c (diff)
parent3baf491ea66ddc77fb949c7aa5e988c318e372c0 (diff)
Merge branch 'master' of https://github.com/adambard/learnxinyminutes-docs into master-cn
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"
+
```