forked from epoch/checkpoint2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
91 lines (67 loc) · 1.46 KB
/
main.rb
File metadata and controls
91 lines (67 loc) · 1.46 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
# 1
def offer_rose(person)
p "Would you take this rose, #{person}, in exchange for giving an old beggar woman shelter from the bitter cold?"
end
offer_rose ("jessie")
# 2
town = {
residents: ["Maurice", "Belle", "Gaston"],
castle: {
num_rooms: 47,
residents: ["Robby Benson"],
guests: []
}
}
town[:residents].delete("Belle")
town[:castle][:guests] << "Belle"
# 3
friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]
friends.each {|friend| p "Belle is friends with #{friend}" }
# 4
lost_boys = [
{name: 'Tootles', age: 11},
{name: 'Nibs', age: 9},
{name: 'Slightly', age: 10},
{name: 'Curly', age: 8},
{name: 'The Twins', age: 9}
]
lost_boys.each do |boy|
puts "#{boy[:age] + 30}"
end
#5
children = ['Wendy', 'John', 'Michael']
darling_children = children.map { |name| "#{name} Darling"}
#6
class Animal
def initialize(new_name)
@name = new_name
end
def get_name
@name
end
def set_name(name)
@name = name
end
def greet
p "hi how are you doing"
end
end
#7
pumba = Animal.new('Pumba')
pumba.greet
#8
def toonify(accent, sentence)
if accent == "daffy"
sentence.gsub 's', 'th'
elsif accent == "elmer"
sentence.gsub 'r', 'w'
elsif accent == "american"
sentence.gsub 'r', 'rrr'
else
sentence
end
end
p toonify("daffy", "so you smell like sausage")
p toonify("elmer", "so you rant like a barbeque")
p toonify("american", "so you water like litter")
p toonify("aussie", "so you smell like sausage")