-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathruby_string.rb
More file actions
57 lines (42 loc) · 1.13 KB
/
ruby_string.rb
File metadata and controls
57 lines (42 loc) · 1.13 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
order = 'wings'
puts order
other_order = "fries"
puts other_order
combo_order_1 = order + other_order
puts combo_order_1
combo_order_2 = "#{order} and #{other_order}"
puts combo_order_2
combo_order_3 = combo_order_2.sub(/fries/, 'waffles with syrup')
puts combo_order_3
excessive_order = 'wings with fries and more fries and even more fries'
puts excessive_order
better_order = excessive_order.sub(/fries/, 'carrots')
puts better_order
best_order = better_order.gsub(/fries/, 'carrots')
puts best_order
def describe_order(order)
if order == 'carrots'
return(order + ' are the best')
else
return(order + ' are the worst')
end
end
some_order = 'hamburger'
some_other_order = 'carrots'
puts describe_order(some_order)
puts describe_order(some_other_order)
first_letter = some_order[0]
puts first_letter
last_letter = some_order[-1]
puts last_letter
healthy_order = 'kale chips with vegan brownies'
iterations = healthy_order.length
puts iterations
iterations.times do |integer|
puts integer
puts healthy_order[integer]
end
iterations.times do |integer|
puts integer
puts healthy_order[healthy_order.length - integer -1]
end