-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1_variables.rb
81 lines (56 loc) · 1.28 KB
/
1_variables.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This is a comment. A one line comment can be done with a #
### NUMBER ###
# Define a Integer with 1
a = 1
puts a
# Use the + operator
number1 = 5
number2 = 10
result = number1 + number2
puts result
# Use the / operator with float variables
number1 = 10.0
number2 = 5.0
result = number1 / number2
puts result
### TEXT ###
# Define a String with 'Hello World'
hello = 'Hello World'
puts hello
### ARRAY ###
#
# Merge different things together like fruits and vegetables
fruits = ['Apple','Orange']
vegetables = ['Cucumber', 'Tomate']
basket = fruits + vegetables
puts basket
# Remove fruits from basket
basket = ['Apple', 'Tomate', 'Orange']
fruits = ['Orange', 'Apple']
basket = basket - fruits
puts basket
# Use the index of lists
# With the following command we get the first element of the array.
puts fruits[0]
# => 'Orange'
### BOOLEAN ###
# Define a boolean
number = 2
is_number_greater = 5 > number
puts is_number_greater
# => false
# Define a if statement
# Boolean is_mentor is true
is_mentor = true
if is_mentor
message = 'Yes you are a mentor.'
puts message
end
# Boolean is_mentor is false and we have a else branch.
is_mentor = false
if is_mentor
message = 'Yes you are a mentor.'
else
message = 'No you are not a mentor, maybe you are a student.'
end
puts message