-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby-intro.rb
More file actions
83 lines (56 loc) · 1.33 KB
/
ruby-intro.rb
File metadata and controls
83 lines (56 loc) · 1.33 KB
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
#This is my first WDI Ruby program
puts "hello world from Ruby"
# NUMBERS
# Integers
1
58
0
-12 # this is negative
# FLoating (decimals)
26.2
9.995
-3.14159
# STRINGS
"Some string"
"goldfish"
'single quotes'
"double quotes"
"here is a contraction: isn't it"
puts 'this is how to work around it isn\'t it'
# 'this won't work'
# BOOLEANS
true
false
## VARIABLES
a = "pineapples"
b = 42
puts a
puts b
# We use snake case for variables in Ruby.
this_is_snake_case = 'it has udnerscores between each word'
# ThisIsCalledCamelCase (used in JavaScript and for classes in Ruby)
#CONSTANTS ARE IN UPPER CASE
ANSWER_TO_LIFE_THE_UNIVERS_AND_EVERYTHING = 42
EARTH_MOON_COUNT = 1
## ARITHMETIC
2 + 2
1 - 5
4 / 2
5 / 2 # Integer division. Will round and give an integer
5.0 / 2 # will give decimal answer since we put a decimal in the division
# above is called Floating point division
5 % 2 # Looks at the remainder. Modulus operator
6 * 9
6 ** 2 # 6 to the power of 2
beth = 4
beth = beth + 2
beth +=2 # does the same as beth = beth + 2
beth -= 30
"Grape" + 'fruit' # concatinates the words
# Interpolation
"The cost is $#{beth} including GST"
# as opposed to: "The cost is $" + beth.to_s + " Including GST"
"The result is #{2 + 4}"
name = 'Juan'
beverage = 'Single malt scotch'
puts "My name is #{ name } and my favourite drink is #{beverage}."