-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex38.rb
More file actions
36 lines (24 loc) · 857 Bytes
/
Copy pathex38.rb
File metadata and controls
36 lines (24 loc) · 857 Bytes
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
ten_things = "Apples Oranges Crows Telephone Light Sugar"
puts "Wait there are not 10 things in that list. Let's fix that."
stuff = ten_things.split(' ')
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"]
# using math to make sure there's 10 items
while stuff.length != 10
#pop takes from end of an array
next_one = more_stuff.pop
puts "Adding: #{next_one}"
# push adds to the end of an array
stuff.push(next_one)
puts "There are #{stuff.length} items now."
end
puts "There we go: #{stuff}"
puts "Let's do some things with stuff."
puts stuff[1]
# that's pretty cool
puts stuff[-1]
# pop can only accept an argument that is not 0...if it's
# 0, you actually don't get anything for some reason
puts stuff.pop()
# join here doesn't list the popped off Corn
puts stuff.join(' ')
puts stuff[3..5].join('#')