1
class PizzaOven
def cook_pizza
"mmm 'za"
end
end
2
class Student
def initialize(name)
@name = name
end
def name
@name
end
end
3
doubled = given * 2
sum = doubled.reduce(:+)
4 git init
1
require 'minitest'
require 'minitest/pride'
require './lib/pizza'
class PizzaTest < Minitest::Test
def test_it_is_always_tasty
pizza = Pizza.new
assert pizza.is_tasty?
end
end
2 Insert the following into the previous PizzaTest class
def test_it_has_one_of_the_right_styles
pizza = Pizza.new
if pizza.style == "supreme" || pizza.style == "mediterranean" || pizza.style == "cheese"
assert pizza.style
end
end
3 git add .
and git commit -m "message
1., 2. & 3.
class Student
attr_reader :attitude, :homework_descriptions
def initialize
@attitude = "cheerful"
@homework_descriptions = []
end
def assign_homework(homework_description)
if attitude == "cheerful"
@attitude = "dubious"
elsif attitude == "dubious"
@attitude = "perturbed"
elsif attitude == "perturbed"
@attitude = "dazed"
end
homework_descriptions << homework_description
end
def assignments
homework_list = homework_descriptions.join(' ')
puts "#{homework_list}"
end
end
1 given
total_assignment_array = students.select_by { |student| student.assignments }
total_assignment_array.join(", ")
1
x: 4
b: 12
1
cd ~/Documents
pizza = File.open("pizza.txt", "r")
puts pizza.readlines
pizza.close
2
cd ~/Documents
pizza = File.open("pizza.txt", "r")
text = pizza.read
total_pizza_lines = text.select("\n").count + 1 # make an array whose elements are each of the instances of "\n" in pizza & add 1 for total number of pizza lines (I'm not sure if you can call `select` on a string)
pizza.close
line_count = File.open("line_count.txt", "w")
line_count.write("#{total_pizza_lines}")
3
require 'minitest'
require 'minitest/pride'
require './lib/corgi'
class PizzaTest < Minitest::Test
attr_reader :corgi
def setup
@corgi = Corgi.new
end
def test_it_exists_without_args
assert_instance_of Corgi, corgi
end
def test_it_can_be_assigned_a_name
assert_equal "Julep", corgi.name("Julep")
end
def test_it_can_be_asked_for_its_name
corgi.name("Lola")
assert_equal "Lola", corgi.name
end
def test_it_can_be_asked_for_its_posture_which_defaults_to_standing
assert_equal "standing", corgi.posture
end
def test_it_can_be_asked_to_lie_down_which_changes_posture_to_laying
assert_equal "laying", corgi.lie_down
assert_equal "laying", corgi.posture
end
end