adjustments

master
Thom Page 10 years ago
parent 580471221f
commit a61ac5fdfc

@ -3,7 +3,7 @@
# WDI-PANTHALASSA
---
Title: Memeory Lane - Part 1<br>
Title: Memory Lane - Part 1<br>
Type: Homework<br>
Duration: One evening<br>
Creator: Thom Page <br>
@ -71,8 +71,20 @@ The commit message should read: <br>
"Commit 4: Bubble Sort".
<hr>
### 5. WORD FREQUENCY
### 5. BONUS: RECURSIVE FACTORIAL
Below are the Javascript instructions. Write your answer in Ruby:
https://github.com/ga-students/wdi-remote/tree/master/unit_01/w02d04/morning_exercise
<hr>
** Commit your work.** <br>
The commit message should read: <br>
"Commit 5: Word Frequency".
<hr>
### 6. BONUS: RECURSIVE FACTORIAL
Below are the Javascript instructions. Write your answer in Ruby:
https://github.com/ga-students/wdi-remote/blob/master/unit_01/w03d03/morning_exercise/recursive_factorial.md
@ -80,5 +92,5 @@ https://github.com/ga-students/wdi-remote/blob/master/unit_01/w03d03/morning_exe
<hr>
** Commit your work.** <br>
The commit message should read: <br>
"Commit 5: Recursive factorial".
"Commit 6: Recursive factorial".
<hr>

@ -2,8 +2,7 @@
Remember all the morning exercises we did in Javascript? Let's revisit these exercises one-by-one. We already have an idea how to approach them having done them before, so let's try to solve them again while also translating them to Ruby.
### 6. WORD FREQUENCY
https://github.com/ga-students/WDI_NYC_Meeseeks/blob/master/unit_02/w05d01/morning_exercise/word_frequency.md
### 7. 100 GOBLINS
NOTE: Using `for` loops is not really the Ruby way. Look up the following looping methods: `.times`, `.step`, and `.each_with_index`.

@ -1,3 +1,17 @@
![ga](http://mobbook.generalassemb.ly/ga_cog.png)
# WDI-PANTHALASSA
---
Title: Ruby classes I <br>
Type: Homework<br>
Duration: One evening<br>
Creator: Thom Page <br>
Course: WDIr-Panthalassa<br>
Competencies: Ruby classes, instance methods, inheritance<br>
---
## RUBY CLASSES
#1. Classes
@ -5,48 +19,86 @@ Watch the short video [here](https://www.youtube.com/watch?v=r6wVziWXYWI). 6 min
##Exercises:
1. Create a Dog class that takes in a name and puts `"Meet #{name}, your new dog!"` on `initialize`.
- Assign the dog a random fur color on initialize
2. Create a Bird class that takes in an adjective and a name and puts `"#{name} is a(n) #{adjective} bird!"` on `initialize`.
- Assign the bird a species at random on initialize
1. Create a Muppet class that takes in a `name` and puts `"This muppet is called #{name}!"` on `initialize`.
- Assign the muppet a random color on initialize.
2. Create a Bird class that takes in an `adjective` and a `name` and puts `"#{name} is a(n) #{adjective} bird!"` on `initialize`.
- Assign the bird a species at random on initialize.
#2. Instance Methods
Watch the short video here [here](https://www.youtube.com/watch?v=c2a2bZf3LH4). 8 mins 22 seconds.
##Exercises:
1. Add instance methods to your dog
- Add a `bark` instance method to your dog that puts `"#{name} is barking!"`
- Add a `growl` instance mthods that puts "Grrrrrrr..."
3. Add instance methods to your bird
- Add a `hungry` method that puts `"#{name} wants a cracker!"`
- Add a `fly` methods that puts `"Flap! #{name} is taking flight!"`
4. Make your bird's ajective and name accessible
* Add instance methods to your Muppet
- Add a `honk` instance method to your muppet that puts `"#{name} is making a honking sound!"`. Test that it works.
- Add a `flail` instance mthods that puts `"#{name} is flailing its arms!"`. Test that it works.
* Add instance methods to your Bird
- Add a `hungry` method that puts `"#{name} wants some regurgitated worms!"`. Test that it works.
- Add a `fly` method that puts `"Flap! #{name} is taking flight!"`. Test that it works.
4. Make your bird's `adjective` and `name` accessible. Test that this works.
#3. Inheritance
Watch the short video [here](https://www.youtube.com/watch?v=BJWcH8Pnafw). 6 mins 56 seconds.
##Exercises:
1. Create a class called `Dessert` that has instance variables of `@name` and `@sugar_content`
2. Give it an instance method of `eat` that puts `"Yum! This #{name} is sooooo delicious!"`
3. Make two new classes called `Pie` and `DeepFriedDessert` that inherit from `Dessert`
4. Give the `DeepFriedDessert` its own `eat` method that instead puts `"Yum! This #{name} is sooo...ack! ugh! *heart-attack*"`
5. Make a new class `IceCream` that inherits from `Dessert` use `super` to get the instance variables of `@name` and `@sugar-content`. Also give `IceCream` its own unique instance variable of `@toppings`
#5. Reps with Classes
### The Universe
What's in a Class? Make a class called `Universe` that:
1. Takes three parameters. These are the three things within the universe. Save these things to instance variables using an `initialize` method.
2. Has an instance variable `@expanding = true`
3. Has an instance variable `@conservation = true`
4. Has a method that will print out all the things in this universe.
5. Has a method called `create` that takes a parameter and will add a new thing to the universe (taken from the parameter). If `conservation = true` then one of the three things in the universe is *replaced* by the new thing. If not, then a new thing is added to the others.
6. Has a method that changes `expanding` to `false` if there are more than ten things in the universe, which means the universe is now contracting . . . (there's no stable universe in this scenario).
7. Has a method called `whim` that changes `conservation` from `true` to `false`
8. Has a method called `crunch` wherein, if `expanding` equals `false`, removes each item from the universe (sets it to null) and prints a string saying the name of the
item and that it has been crunched due to gravity. When the final item remains, remove that item and print "The Universe has ended."
Test out your Universe by instantiating a `new` Universe with its parameters and running your commands.
#3. Class Methods and 'Self'
Watch the short video [here](https://www.youtube.com/watch?v=0r93ZhzpeqI). 8 mins 28 seconds.
##Exercises:
1. Experiment with `self`
* Experiment with `self`
- Add a class method `self.what_is_self` to your Bird class and have it put `self`.
- Add an instance method `what_is_self` to your Bird class and have it put `self`.
- Try calling both of these methods in Pry and see what they return.
2. Add a class method to make puppies!
- add an instance variable of quality to your dog (here we will put a characteristic like 'playful', 'brave', 'loyal')
- add an instance variable that adds a characteristic like 'playful', 'brave', 'loyal'
- add a class method of `make_puppy` to your dog class that takes in two dogs and returns a new dog.
- the new dog should have fur color of the first dog and the quality of the second dog.
- make puppies!
-----------
#4. Inheritance
Watch the short video [here](https://www.youtube.com/watch?v=BJWcH8Pnafw). 6 mins 56 seconds.
#X. Ruby problems
100 goblins
caesar cipher
##Exercises:
1. Create a class called `Dessert` that has instance variables of `@name` and `@sugar_content`
2. Give it an instance method of `eat` that puts `"Yum! This #{name} is sooooo delicious!"`
3. Make two new classes called `Pie` and `DeepFriedDessert` that inherit from `Dessert`
4. Give the `DeepFriedDessert` its own `eat` method that instead puts `"Yum! This #{name} is sooo...ack! ugh! *heart-attack*"`
5. Make a new class `IceCream` that inherits from `Dessert` use `super` to get the instance variables of `@name` and `@sugar-content`. Also give `IceCream` its own unique instance variable of `@toppings`

@ -1,146 +0,0 @@
# RUBY AND SINATRA PRACTISE
![rs](https://thejewelerblog.files.wordpress.com/2014/07/guysanddolls1.jpg)
Make a homework.rb file in your repo for tonight and put the answers
to Part One in there.
## PART ONE: METHODS AND CLASSES
### 1. Palindrome
Make a ruby method that returns true if a string is a palindrome, false if not. Make sure it returns the correct result for words with capital letters.
### 2. The Caesar Cipher
From Wikipedia:
> In cryptography, a Caesar cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. The method is named after Julius Caesar, who used it in his private correspondence.
We're going to implement a simple Caesar Cipher called ROT13 ("rotate by 13 places"). The transformation can be represented by aligning two alphabets, like so:
```
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: nopqrstuvwxyzabcdefghijklm
```
ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption. ROT13 is used in online forums as a means of hiding spoilers, punchlines, and puzzle solutions from the casual glance.
**Directions:**
Read up on the difference between **class methods** and **instance methods** here: (http://www.railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/). Just read through the first two examples, no need to dwell.
Make a class called `Cipher`, and implement a **class method** `encode` that takes a word as an argument and returns its ciphertext using ROT13.
You can then call the class and its method and get a result as follows:
```
Cipher.encode("hello")
=> "uryyb"
Cipher.encode("peter")
=> "crgre"
```
### 3. The Universe
Make a class called `Universe` that:
1. Takes three parameters. These are the three things within the universe. Save these things to instance variables using an `initialize` method.
2. Has an instance variable `@expanding = true`
3. Has an instance variable `@conservation = true`
4. Has a method that will print out all the things in this universe.
5. Has a method called `create` that takes a parameter and will add a new thing to the universe (taken from the parameter). If `conservation = true` then one of the three things in the universe is *replaced* by the new thing. If not, then a new thing is added to the others.
6. Has a method that changes `expanding` to `false` if there are more than ten things in the universe, which means the universe is now contracting . . . (there's no stable universe in this scenario).
7. Has a method called `whim` that changes `conservation` from `true` to `false`
8. Has a method called `crunch` wherein, if `expanding` equals `false`, removes each item from the universe (sets it to null) and prints a string saying the name of the
item and that it has been crunched due to gravity. When the final item remains, remove that item and print "The Universe has ended."
Test out your Universe by instantiating a `new` Universe with its parameters and running your commands.
-----------
## PART TWO: SINATRA
### Sinatra Grocery Store II
Build a Grocery Store App with Sinatra. Using parameters, the app should simply return the cost of the grocery in question. Remember to quit and reload your app when you make changes! Remember that ctrl + C quits out of your server! Remember to load your server at localhost:4567 in your browser to see the result!
Examples:
| Sample Path | Info On Page |
| ----------- | ------------ |
| /store/lettuce | Lettuce costs: $7 |
| /store/gruyere | Gruyere costs: $110 |
| /store/mussels | Mussels costs: $41 |
| /store/plantains | Plantains costs: $5 |
| /store/cashews | Cashews costs: $20 |
| /store/icecream | Icecream costs: $9 |
| /store/knish | Knish costs: $3 |
| /store/baklava | Baklava costs: $2.5 |
### Setup
Make a `store.rb` file. Remember to `require sinatra` at the top of your `store.rb` file.
### Part 1:
Start by preparing `store.rb` and getting the eight routes to work with the correct message as in the table above.
### Part 2:
Using this as a clue:
```
get '/hello/:name/' do
"Why, hello #{params[:name]}"
end
```
Make it so you can choose what the price of your groceries will be by entering it into the URL bar.
For example `store/lettuce/7` will show: `Lettuce costs: $7`
### Part 3:
Using this as a clue:
```
get '/:name/:city' do
"Why, hello #{params[:name]} from #{params[:city]}"
end
```
Make it so you can enter any grocery that could possibly exist, and any price, and get the result as above.
### Part 4:
1. Make a route that redirects `'/'` to `'/store'`.
2. Make a 'not found' message that appears if the route is not found (404).
#### End
Loading…
Cancel
Save