mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Updated location, and reduced examples
also added array [] access example.
This commit is contained in:
parent
8c89f3f608
commit
99e1c31b19
@ -4,6 +4,7 @@ filename: learnruby.rb
|
|||||||
contributors:
|
contributors:
|
||||||
- ["David Underwood", "http://theflyingdeveloper.com"]
|
- ["David Underwood", "http://theflyingdeveloper.com"]
|
||||||
- ["Joel Walden", "http://joelwalden.net"]
|
- ["Joel Walden", "http://joelwalden.net"]
|
||||||
|
- ["Luke Holder", "http://twitter.com/lukeholder"]
|
||||||
---
|
---
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@ -30,6 +31,11 @@ You shouldn't either
|
|||||||
10 * 2 #=> 20
|
10 * 2 #=> 20
|
||||||
35 / 5 #=> 7
|
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
|
# Special values are objects
|
||||||
nil # Nothing to see here
|
nil # Nothing to see here
|
||||||
true # truth
|
true # truth
|
||||||
@ -121,6 +127,12 @@ array = [1, "hello", false] #=> => [1, "hello", false]
|
|||||||
array[0] #=> 1
|
array[0] #=> 1
|
||||||
array[12] #=> nil
|
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
|
# From the end
|
||||||
array[-1] #=> 5
|
array[-1] #=> 5
|
||||||
|
|
||||||
@ -313,21 +325,4 @@ dwight.name #=> "Dwight K. Schrute"
|
|||||||
# Call the class method
|
# Call the class method
|
||||||
Human.say("Hi") #=> "Hi"
|
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…
Reference in New Issue
Block a user