-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathandrew.rb
More file actions
88 lines (62 loc) · 1.46 KB
/
andrew.rb
File metadata and controls
88 lines (62 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
require 'pry'
# Question 1
def offer_rose(person)
"Would you take this rose, #{person} in exchange for giving an old beggar woman shelter from the bitter cold?"
end
# Question 2
town = {
residents: ["Maurice", "Belle", "Gaston"],
castle: {
num_rooms: 47,
residents: ["Robby Benson"],
guests: []
}
}
town[:residents].delete("Belle")
town[:castle][:residents].push("Belle")
# Question 3
friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]
friends.each { |friend| puts "Belle is friends with #{friend}" }
# Question 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|
boy[:age] = boy[:age] + 30
end
# Question 5
children = ['Wendy', 'John', 'Michael']
darling_children = children.map { |a| "#{a} Darling" }
# Question 6
class Animal
def initialize(name) # is there a way to require this as a string?
@name = name
end
def greet
return "Hi my name is #{@name}" # unsure what this method should do?
end
def get_name
@name
end
def set_name(name)
@name = name
end
end
# Question 7
pumba = Animal.new("pumba")
# Question 8
def toonify(accent, sentence)
if accent == "daffy"
return sentence.gsub("s", "th")
end
if accent == "elmer"
return sentence.gsub("r", "w")
else
return sentence
end
end
binding.pry