-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-variables.rb
50 lines (27 loc) · 930 Bytes
/
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
# Ruby is a friendly programming language that's all the rage these days.
# It is easy to understand, and has a great community to help you when you get stuck.
# Let's start with the basics.
# 1 - Assigning variables.
# Variables store stuff by name. I've stored "Wojtek" in the variable my_name:
my_name = "Wojtek"
# I'll print the variable to the screen now:
puts my_name
# You can perform tons of operations on variables:
greeting = "Hello "
# Here I'm 'adding' my name to a greeting:
puts greeting + my_name
# Here I'm doing the same but with numbers:
x = 10
y = 5
puts x + y
# I can also compare stuff, using the equality operator, ==
your_name = "Jethroe"
puts your_name == my_name
# And compare sizes using the < and > operators.
# Using <= and >= is like saying 'less/greater than or equal to'
6 < 7 # true
6 < 9 # false
6 < 6 # false
6 <= 6 # true
# You can also evaluate inequality:
6 != 7 # true