1. Tipus: Nombres, Strings, Booleans
my_num = 25 # Add your code here!
my_boolean = true # And here!
my_string = "Ruby" # Also here.
Output
"Ruby"
2. Asignar valor a una variable i canviar la variable
my_num = 5
my_num = 100
Output
100
3. Declarar una variabla i operar amb ella
my_num = 100
my_num / 5
Output
20
4. No necessitem parèntesi
puts "What's up?"
print "Oxnard Montalvo"
Output
What's up?
Oxnard Montalvo
5. Mètodes
"I love espresso".length
Output
15
"Eric".reverse
Output
"cirE"
puts "eric".upcase
puts "eric".downcase
Output
ERIC
eric
6. Una línea de comentari
# I'm a full line comment!
"Eric".length # I'm a comment, too!
Output
4
7. Multilínies comentades
=begin
I'm a comment!
I don't need any # symbols.
=end
Output
8. Declarant variables
my_name = "Eric"
my_age = 26
hungry = true
Output
true
9. Definim variables que operen
sum = 13 +379
product = 923 * 15
quotient = 13209 / 17
Output
777
10. Encadenant mètodes
name = "Antoni"
puts name.downcase.reverse.upcase
Output
INOTNA