- fork this repo
- clone your repo to your computer
- make a new directory with your name
- put your answers in this directory
- make a commit for every question
- make a pull request before time is up!!!
Define a method called offer_rose, which should take one argument named person (String).
When called the method should print to the terminal:
"Would you take this rose, person, in exchange for giving an old beggar woman shelter from the bitter cold?" -->
def offer_rose string
puts "Would you take this rose, person, in exchange for giving an old beggar woman shelter from the bitter cold?"
end
offer_rose('person')
Assume the following hash...
town = {
residents: ["Maurice", "Belle", "Gaston"],
castle: {
num_rooms: 47,
residents: ["Robby Benson"],
guests: []
}
}Using Ruby...
- Remove "Belle" from
residents - Add "Belle" to the
guestsarray Type your solution directly below this line:
town[:residents].delete('Belle') town[:guests] = ['Belle']
Assume you have an array of strings representing friends' names...
friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]Using a loop and string interpolation, print each string in friends to the Terminal...
"Belle is friends with Chip Potts"
"Belle is friends with Cogsworth"
"Belle is friends with Lumière"
"Belle is friends with Mrs. Potts"friends.each do |friend| p "Belle is friends with #{friend}" end
Assume the following array of hashes:
lost_boys = [
{name: 'Tootles', age: 11},
{name: 'Nibs', age: 9},
{name: 'Slightly', age: 10},
{name: 'Curly', age: 8},
{name: 'The Twins', age: 9}
]Use .each to iterate over the lost_boys array and increase each boy's age by 30 years.
lost_boys.each { |name| name[:age] += 10 }
Assume the following array:
children = ['Wendy', 'John', 'Michael']Use .map to iterate through the children array and add Darling to the end
of their names. Assign the returned array to a variable called darling_children.
Example: Wendy should become Wendy Darling in the new array.
darling_children = children.map {|name| darling_children = [] name = "#{name} Darling" }
Define a Ruby class called Animal. Each Animal should have...
-
A
name(String) attribute -
A
greetinstance method -
The ability to "get" and "set"
nameclass Animaldef set_name @name = get_name().chomp end
def get_name @name = gets end
def greets "#{@name} says hello" end
end
animal = Animal.new
Create a new Animal instance with the name "Pumba" an assign it to a variable named pumba.
Write a method called toonify that takes two parameters, accent and sentence.
- If
accentis the string"daffy", return a modified version ofsentencewith all "s" replaced with "th". - If the accent is
"elmer", replace all "r" with "w". - Feel free to add your own accents as well!
- If the accent is not recognized, just return the sentence as-is.
toonify "daffy", "so you smell like sausage"
#=> "tho you thmell like thauthage"Call the method twice with different arguments