-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson-01.rb
99 lines (76 loc) · 2.9 KB
/
lesson-01.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'awesome_print'
#Basics of Ruby Data structures
#Uncomment each block in order to see
#Arrays
# Arrays are simply a list of elements. A list of names showing all employees could look like ,
# namesOfEmployees = ["Bob", "Don", "Sue", "Ralph"]
# this would be a list of strings. In ruby you don't have to define the types that are going to be included in the array
# Consider an array that describes the prizes in a slot machine that pays out in credit or an item
# availPrizes = ["IPad", 20, "PS4", 50.00, "Laptop"]
arr = []
# ap "See above how we initialized an empty array on ln 5"
# ap "and below is the output of the empty array."
# ap arr
# ap "*"*25
# arr << "Ashley"
# ap "We put a string into the first position of the array and printed it below. Arrays are indexed starting at zero."
# print arr
# ap "*"*25
arr << "Ashley"
arr << 85
# arr << {numberInObject:12}
# ap "We added a few other elements to the array using the << (push) notation. Note that Ruby doesn't mind having many different object types in an individual array."
# print arr
# puts
# print arr[1]
# puts
# ap "*"*25
# ap "Play with the following array commands and see what they do to the array"
# #init contents of the array
# arr << "Ashley"
# arr << 85
# arr << {numberInObject:12}
#array commands below
# arr << element #Push / Append an element onto the end of the array
# arr.push(element) #Same as previous
#
# arr.clear #Erase all elements in arr.
# arr.first #Returns the first element in arr
# arr.last #Returns the last element in arr
# puts arr.sample #Returns a random element in arr
## more at https://www.shortcutfoo.com/app/dojos/ruby-arrays/cheatsheet
#Strings
# Strings are best described as anything inside of quotes. These are usually characters, words, or sentences that have
# no intention of math ever occurring on them.
# firstName = 'Ashley "the knucklhead"\'s suitcase '
# lastName = 'McGoober'
# otherLastName = 'Mcgoober'
# puts "lastName:#{lastName.upcase} is equal to otherLastName:#{otherLastName.upcase}"
# puts lastName.upcase == otherLastName.upcase
# Both single quote (') and double quote (") are allowed to define strings in Ruby. Strings share MANY similarities to Arrays,
# and it makes sense if you consider that a string is really just an array of single characters.
# ['A', 's', 'h', 'l', 'e', 'y']
#Integers
# Integers are whole numbers and are not surrounded by quotation marks.
# currentYear = 2017
# currentYear_s = '2017'
# puts 4 * 4
# puts '4' * 4
# puts '4' * '4'
# Integers work intuitively for the most part
# nextYear = currentYear + 1
#Hashes / Dictionary / Object
employee = {
:name => "Ashley",
:gender => "Female",
:age => 26,
:skills => ["Ruby", "Gardening", "Nose-picking"]
}
puts employee
# employee[:retirement] = "401k"
print employee.keys
##############################
#Other less often used types
##############################
#Floating Point Numbers
#Range