-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdulyruby
More file actions
159 lines (96 loc) · 2.1 KB
/
dulyruby
File metadata and controls
159 lines (96 loc) · 2.1 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Temp A
[]
['Good', 'Morning', 'Vietnam']
[3, [2, 5], 64]
[1.6, true, 'corundum']
# Temp B
my_array = [3, 4, 7, 3, 6, 0]
print my_array[4]
# Temp BB
mult_array = [[1, 2], [3, 4], [5, 6]]
print mult_array[1][0]
# Temp C
my_array = my_array << 23
print my_array
# Temp D
my_array[2] = 99
print my_array
# Temp E
your_array = [12, 2, 66, 3]
our_array = my_array + your_array
print our_array
# Temp F
for var in 1...10
puts var
end
# Temp G
12.times {puts "Huzzah!"}
# Temp H
counter = 0
while counter < 5
puts counter
counter += 1
end
# Temp I
num = 0
until num == 5
puts num
num += 1
end
# Temp J
array = ['five', 'four', 'three', 'two', 'one']
array.each { |element| puts element }
# Temp K
multi_array = [[3, 54], ['Hello ', 'world!'], [true, false]]
multi_array.each {|sub_array| sub_array.each {|var| puts var}}
# Temp L
legends = {'Smalls' => 'Scotty',
'The Jet' => 'Benny',
'Ham' => 'Hamilton',
'Squints' => 'Michael',
'Yeah-Yeah' => 'Alan'}
# Temp M
legends['Repeat'] = 'Tommy'
# Temp N
puts legends['Squints']
# Temp O
puts legends['The Beast']
# Temp P
fave_lang = {'Keith' => 'Javascript',
'Erik' => 'Python',
'Jimmy' => 'PHP',
'Graeme' => '.NET',
'Scott' => 'Ruby'}
fave_lang.each {|person, language| puts person + ' loves using ' + language}
# Temp Q
my_hash = {javascript: 'clunky',
python: 'simple',
ruby: 'elegant'}
# Temp R
puts 'string'.object_id
puts 'string'.object_id
puts :symbol.object_id
puts :symbol.object_id
# Temp S
yelp_reviews = {nori: 3.5,
mesob: 4.5,
spice2: 4.0,
bamboo: 3.0,
fresco: 2.0}
best_food = yelp_reviews.select {|name, rating| rating > 3}
puts best_food
# Temp T
def greeting
puts "Hello world!"
end
# Temp U
def cube n
puts n ** 3
end
puts cube(7)
# Temp V
[true, false, true, true, false].each {|bool| puts bool}
# Temp W
drinks = ['red bull', 'monster', 'full-throttle', 'amp', 'rockstar']
drinks.sort! {|drink1, drink2| drink1 <=> drink2}
puts drinks