mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 16:23:37 +03:00
Merge pull request #564 from arikrak/patch-2
Added some example code and resources.
This commit is contained in:
commit
a045c44c98
@ -8,6 +8,8 @@ contributors:
|
|||||||
- ["Tristan Hume", "http://thume.ca/"]
|
- ["Tristan Hume", "http://thume.ca/"]
|
||||||
- ["Nick LaMuro", "https://github.com/NickLaMuro"]
|
- ["Nick LaMuro", "https://github.com/NickLaMuro"]
|
||||||
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
|
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
|
||||||
|
- ["Ariel Krakowski", "http://www.learneroo.com"]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@ -33,6 +35,7 @@ You shouldn't either
|
|||||||
8 - 1 #=> 7
|
8 - 1 #=> 7
|
||||||
10 * 2 #=> 20
|
10 * 2 #=> 20
|
||||||
35 / 5 #=> 7
|
35 / 5 #=> 7
|
||||||
|
2 ** 5 #=> 32
|
||||||
|
|
||||||
# Arithmetic is just syntactic sugar
|
# Arithmetic is just syntactic sugar
|
||||||
# for calling a method on an object
|
# for calling a method on an object
|
||||||
@ -79,6 +82,10 @@ placeholder = "use string interpolation"
|
|||||||
"I can #{placeholder} when using double quoted strings"
|
"I can #{placeholder} when using double quoted strings"
|
||||||
#=> "I can use string interpolation when using double quoted strings"
|
#=> "I can use string interpolation when using double quoted strings"
|
||||||
|
|
||||||
|
# Combine strings, but not with numbers
|
||||||
|
"hello " + "world" #=> "hello world"
|
||||||
|
"hello " + 3 #=> TypeError: can't convert Fixnum into String
|
||||||
|
"hello " + 3.to_s #=> "hello 3"
|
||||||
|
|
||||||
# print to the output
|
# print to the output
|
||||||
puts "I'm printing!"
|
puts "I'm printing!"
|
||||||
@ -247,6 +254,22 @@ else
|
|||||||
puts "Alternative grading system, eh?"
|
puts "Alternative grading system, eh?"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#=> "Better luck next time"
|
||||||
|
|
||||||
|
# cases can also use ranges
|
||||||
|
grade = 82
|
||||||
|
case grade
|
||||||
|
when 90..100
|
||||||
|
puts "Hooray!"
|
||||||
|
when 80...90
|
||||||
|
puts "OK job"
|
||||||
|
else
|
||||||
|
puts "You failed!"
|
||||||
|
end
|
||||||
|
|
||||||
|
#=> "OK job"
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
def double(x)
|
def double(x)
|
||||||
@ -474,3 +497,12 @@ Something.qux # => NoMethodError: undefined method `qux'
|
|||||||
Something.new.bar # => NoMethodError: undefined method `bar'
|
Something.new.bar # => NoMethodError: undefined method `bar'
|
||||||
Something.new.qux # => 'qux'
|
Something.new.qux # => 'qux'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Additional resources
|
||||||
|
|
||||||
|
- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
|
||||||
|
- [Official Documentation](http://www.ruby-doc.org/core-2.1.1/)
|
||||||
|
- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
|
||||||
|
- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user