Last active
February 9, 2017 17:12
-
-
Save dannyradden/2d411b234614c949561c72a4303cf433 to your computer and use it in GitHub Desktop.
Week 2 and 3 Diagnostic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
``` | |
class PizzaOven | |
def cook_pizza | |
puts "mmm 'za" | |
end | |
end | |
``` | |
2. | |
``` | |
class Student | |
def initialize(name) | |
@name = name | |
end | |
def name | |
@name | |
end | |
end | |
``` | |
3. | |
``` | |
array = [1,2,3,4,5] | |
array.map! { |number| number * 2 } | |
sum = array.inject(:+) | |
``` | |
4. git init | |
**Pizza** | |
1. | |
``` | |
def test_if_tasty | |
p = Pizza.new | |
assert p.is_tasty? | |
end | |
``` | |
2. | |
``` | |
def test_if_tasty | |
p = Pizza.new | |
list = ["supreme", "mediterranean", "cheese"] | |
assert list.include?(p.style) | |
end | |
``` | |
3. | |
``` | |
git add . | |
git commit -m "this is a commit message" | |
``` | |
**Student** | |
1. | |
``` | |
class Student | |
attr_reader :attitude | |
def initialize | |
@attitude = "cheerful" | |
end | |
end | |
``` | |
2. | |
``` | |
def assign_homework | |
if attitude = "cheerful" | |
attitude = "dubious" | |
elsif attitude = "dubious" | |
attitude = "perturbed" | |
else | |
attitude = "dazed" | |
end | |
end | |
``` | |
3. | |
``` | |
def assign_homework(string) | |
if attitude = "cheerful" | |
attitude = "dubious" | |
elsif attitude = "dubious" | |
attitude = "perturbed" | |
else | |
attitude = "dazed" | |
end | |
@assignments = [] | |
@assignments << string | |
def assignments | |
@assignments.join(", ") | |
end | |
end | |
``` | |
4. | |
``` | |
all_assignments = students.map {|student| student.assignments} | |
all_assignments.join(", ") | |
``` | |
5. | |
``` | |
x: 4 | |
b: 12 | |
``` | |
1. | |
``` | |
file = File.open("~/Documents/pizza.txt", 'r').read | |
p file | |
``` | |
2. | |
``` | |
file = File.open("~/Documents/pizza.txt", 'r').read | |
count = file.lines.count | |
File.open("~/Documents/line_count.txt", 'w').write = count | |
``` | |
3. | |
``` | |
def test_no_args | |
assert Corgi.new | |
end | |
def test_assign_name | |
dog = Corgi.new | |
dog.name = "Fluffy" | |
assert_equal "Fluffy", dog.name | |
end | |
def test_ask_name | |
dog = Corgi.new | |
assert dog.name.exist? | |
end | |
def test_ask_posture | |
dog = Corgi.new | |
assert_equal "standing", dog.posture | |
end | |
def test_assign_posture | |
dog = Corgi.new | |
dog.posture = "laying" | |
assert_equal "laying", dog.posture | |
end | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment