- Fork this repo
- Clone your fork
- Fill in your answers by writing in the appropriate area or, for multiple-choice questions, placing an 'x' in the square brackets
- Add/Commit/Push your changes to Github
- Open a pull request
For questions 1-4, you must test your code before filling in an answer. You can do this by creating and running your own app.rb
file.
Only place your answer between the backticks provided for you throughout the checkpoint.
Define a method called offer_rose
, which should take one argument named person
(String).
When called the method should print "Would you take this rose, person
, in exchange for giving an old beggar woman shelter from the bitter cold?" to the Terminal.
Demonstrate calling the method, passing in "young prince" as the argument.
# Your code goes here...
def offer_rose 'person'
print "Would you take this rose, #{person}, in exchange for giving an old beggar woman shelter from the bitter cold?"
end
### Question 2
Assume the following hash...
```ruby
town = {
residents: ["Maurice", "Belle", "Gaston"],
castle: {
num_rooms: 47,
residents: "Robby Benson",
guests: []
}
}
Using Ruby...
- Remove "Belle" from
residents
- Add "Belle" to the
guests
array
# Your code goes here...
[:residents].delete_at(1)
[:guest].push(Belle)
### Question 3
Assume you have an array of strings representing friends' names...
```rb
friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]
Using .each
and string interpolation, print the following text 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
# Your code goes here...
loop freinds.each do |name|
puts "Belle is friends with #{name}"
end
## Ruby OOP
### Question 4
Create Ruby classes for `Animal` and `Lion`. Each `Animal` should have...
- A `name` (String) attribute
- A `greet` instance method
- The ability to "get" and "set" `name`
Create a new `Animal` instance with the name "Pumba".
Make the `Lion` inherit from the `Animal` class. The `Lion` class should have a `pack` class variable that holds references to each instance created.
Each lion should have...
- A `king` (Boolean) attribute
- If the instance's `name` is "Simba", set the `king` attribute to `true`
Create a new lion instance with the name "Simba".
```rb
# Your code goes here...
Describe what an ERD is and why we create them for applications. Also give an example what the attributes and relationships might be for the following entities (no need to draw an ERD)...
- Genie
- Lamp
- Person
- Pet
Your answer goes here...
Entity Relationship Diagram.
- Genie - # of wishes - activation procedures -
- Lamp - physical base, attachements - eletrical componenet, wire to outlet - bulb for electrical light outlet
- Person - body anatomy, limb, organs - intelligent life form - dangerous to earth and mother nature.
- Pet - so called man's best friend - society tamed pet - belongs to animal kingdom
### Question 6
Describe what a schema is and how we represent a one-to-many relationship in a
SQL database.
Your answer goes here... a schema is a collection of databases and information.
a one to many relationship is for example a member of the police force 'to' a 'many' - law enforcement agency.
Or
college student - college courses
Consider a class Person
that inherits from ActiveRecord::Base
and has the following schema...
class Person < ActiveRecord::Base
end
CREATE TABLE persons(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
age INT NOT NULL
);
Write Ruby code that will create an instance of a person...
# Your code goes here...
Assuming the Person
class from the previous question, write Ruby code that will query for any person that is 15 years of age...
# Your code goes here...
Write a route in Sinatra that will print "Hello world" in the web browser at the following URL: http://localhost:4567/oh_hello
# Your code goes here...