Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Complete Final #129

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ Week 5
* Rake

Week 6
* Mid-term due!
* Projects intro
* Gems
* CI

Week 7
* Mid-term due!
* Cucumber
* Testing frameworks
* Refactoring

Week 8
* Metaprogramming
Expand All @@ -50,7 +51,6 @@ Week 8

Week 9
* Exceptions
* Refactoring
* Review

Week 10
Expand Down
3 changes: 3 additions & 0 deletions ft.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
file = File.new('my_output.txt', 'w')
file.write("Hello World!")
file.close
1 change: 1 addition & 0 deletions my_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
7 changes: 7 additions & 0 deletions week1/class_materials/new_printer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe 'NamePrinter Application' do
context 'When Renee is logged in' do
it 'should say Renee' do
"Renee".should == "Renee"
end
end
end
101 changes: 54 additions & 47 deletions week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,91 +1,98 @@
# encoding: utf-8
# # encoding: utf-8

describe "The Rspec ruby gem" do

context "Domain Specific Language" do
# context "Domain Specific Language" do

it "creates examples with the #it keyword" do
# it "creates examples with the #it keyword" do

# this test code passes, so this example passes
1.should eq 1
# # this test code passes, so this example passes
# 1.should eq 1

end
# end

it "has keywords like #context, and #describe to help organize the spec, or specification" do
# it "has keywords like #context, and #describe to help organize the spec, or specification" do

# test code goes here
(1+2).should eq 3
# # test code goes here
# (1+2).should eq 3

end
# end

it "has easily readable methods like #should to test any object" do
# it "has easily readable methods like #should to test any object" do

"Hello".should eq "Hello"
# "Hello".should eq "Hello"

end
# end

it "has #should_not to test for negative cases" do
# it "has #should_not to test for negative cases" do

1.should_not eq 2
# 1.should_not eq 2

end
# end

it "creates readable predicate methods" do
# it "creates readable predicate methods" do

# Integers have #zero? and #nil? predicate methods, so
# rspec automatically supports the #be_zero and #be_nil parameter to #should_not method
1.should_not be_zero
1.should_not be_nil
# # Integers have #zero? and #nil? predicate methods, so
# # rspec automatically supports the #be_zero and #be_nil parameter to #should_not method
# 1.should_not be_zero
# 1.should_not be_nil

end
# end

it "alerts you when examples fail" do
# it "alerts you when examples fail" do

# When this example fails,
# it will show "expected" as 2, and "actual" as 1
1.should eq 2
# # When this example fails,
# # it will show "expected" as 2, and "actual" as 1
# 1.should eq 2

end
# end

it "supports placeholder examples that lack code (like this one)"
# it "supports placeholder examples that lack code (like this one)"

it "requires that examples use expectations (like #should) to work properly" do
# it "requires that examples use expectations (like #should) to work properly" do

# The following expression is false.
# However, this example PASSES because no expectation was created.
true == false
# # The following expression is false.
# # However, this example PASSES because no expectation was created.
# true == false

# The following line of code is correct, and would cause the example to fail:
# true.should == false
# # The following line of code is correct, and would cause the example to fail:
# # true.should == false

# Lesson: It's easy to write bad tests.
# # Lesson: It's easy to write bad tests.

end
# end

it "should count the characters in my name" do
"Renée".should have(5).characters
end
# it "should count the characters in my name" do
# "Renée".should have(5).characters
# end

it "should check how to spell my name" do
"Renée".should include("ée")
end
# it "should check how to spell my name" do
# "Renée".should include("ée")
# end

end
# end

context "Examples for in-class test exploration" do
it "should know order of operations" do
# Fix the Failing Test
# Order of Operations is Please Excuse My Dear Aunt Sally:
# Parentheses, Exponents, Multiplication, Division, Addition, Subtraction
(1+2-5*6/2).should eq -13
(1+1-5*6/2).should eq -13
end
it "should count the characters in your name" do
pending
name = "Jordan"

name.should have(6).characters

end

it "should check basic math"
it "should check basic math" do
(2+2).should eq 4
end

it "should check basic spelling"
it "should check basic spelling" do
"Hello".should include('llo')
end

end

Expand Down
17 changes: 17 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
An object is the basic unit of an object oriented programming languages. They're used to store data and call methods assigned to them.

2. What is a variable?
A variable is a reference to a value.

3. What is the difference between an object and a class?
A class is a particular kind of object that is meant to generate "instances" (also objects) of itself. The class defines not only how the class behaves, but how its instances behave.

4. What is a String?
A string is text data. They can be assigned to variables and passed into arguments.

5. What are three messages that I can send to a string object? Hint: think methods
split(','), rstrip, to_i

6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
1) Surround some text with single quotes or inside a %q( ) block (you can use any non alphanumeric character as the delimiter in the block). These do not allow string interpolation and most escape sequences
Examples:
string = 'weeee'
string = %q< weeee >
string = %q# weeee #
string
#=> "weeee"
2) Surround some text with DOUBLE quotes or inside a %Q( ) or %( ) block. This enables string interpolation and most escape sequences.
Examples
string = "It\'s math time 1+1 = #{1+1}"
string
#=> "It's math time 1+1 = 2"
9 changes: 5 additions & 4 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
before(:all) do
@my_string = "Renée is a fun teacher. Ruby is a really cool programming language"
end
it "should be able to count the charaters"
it "should be able to count the characters" do
@my_string.should have(66).characters
end
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
result = @my_string.split('.')
result.should have(2).items
end
it "should be able to give the encoding of the string" do
pending 'helpful hint: should eq (Encoding.find("UTF-8"))'
@my_string.encoding.should eq (Encoding.find("UTF-8"))
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
A hash is an set of key and value pairs, while an array is a set of only values

2. When would you use an Array over a Hash and vice versa?
You would use an array when you have a list of an unknown number of similar objects that can be treated the same, you would use a hash when you will need to access specific objects out of the collection.

3. What is a module? Enumerable is a built in Ruby module, what is it?
Modules contain code that can be mixed into objects with the 'include' method. They can also be used to nest classes under namespaces.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
Clases can only inherit directly from one superclass, but it also inherits for it's superclass's superclass, that superclass's superclass, so on and so forth, until you reach the BasicObject. If you need to inject more code into a class and can't put in it's superclass lineage, then mix it in with a module

5. What is the difference between a Module and a Class?
A class creates instances of itself, a module is a collection of code you can mix into objects or use as a namespace.
26 changes: 26 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module SimonSays
def echo(what)
what
end

def shout(what)
what.upcase
end

def repeat(what, times = 2)
return_value = []
times.times do |x|
return_value << what
end
return_value.join(' ')
end

def start_of_word(what, number_of_letters)
what[0..(number_of_letters - 1)]
end

def first_word(what)
what.split(' ')[0]
end

end
2 changes: 1 addition & 1 deletion week2/homework/simon_says_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Hint: require needs to be able to find this file to load it
require "./simon_says.rb"
require_relative "./simon_says"

describe SimonSays do
include SimonSays # Hint: Inclusion is different than SimonSays.new (read about modules)
Expand Down
2 changes: 1 addition & 1 deletion week3/exercises/monster.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require './named_thing.rb'
require_relative 'named_thing.rb'
class Monster
include NamedThing
attr_accessor :vulnerabilities, :dangers
Expand Down
28 changes: 28 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Calculator
def sum(array)
return 0 if array.empty?
array.inject(:+)
end

def multiply(*args)
args.flatten.inject(:*)
end

def pow(n, power)
return_val = 1
power.times do
return_val *= n
end
return_val
end

def fac(n)
return_val = 1
while n > 0
return_val*=n
n-=1
end
return_val
end

end
4 changes: 2 additions & 2 deletions week3/homework/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

it "raises one number to the power of another number" do
p = 1
32.times{ p *= 2 }
@calculator.pow(2,32).should eq p
32.times{ p *= 2 }
@calculator.pow(2,32).should eq p
end

# http://en.wikipedia.org/wiki/Factorial
Expand Down
6 changes: 6 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ Please Read:
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants

1. What is a symbol?
A symbol is a unique, unchangable name.

2. What is the difference between a symbol and a string?
A symbol cannot be changed.

3. What is a block and how do I call a block?
A block is a set of code that you pass to a method. Call those code in the method definition with the 'yield' keyword.

4. How do I pass a block to a method? What is the method signature?
Put the block after the arguments in a do;end block or in between curly brackets.
The method signature is the way a method is set to accept arguments and blocks.

5. Where would you use regular expressions?
When validating a string to ensure it fits a certain format (E.G. checking to see if a string works as a URL or credit card), or isolating a part of a string that fits in a particular pattern.
Empty file added week4/class_materials/person.rb
Empty file.
11 changes: 11 additions & 0 deletions week4/exercises/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Worker
class << self
def work(times = 1, &block)
times.times do |x|
return yield if (x += 1) == times
yield
end
end
end

end
11 changes: 11 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
Ruby uses the methods in the IO class, along with it's subclass File, to read files. Call File.open() or File.new() and pass the path to the file, and it'll return an IO object that can be read and altered according to the "mode" (e.g. 'w' for write) you pass it.

2. How would you output "Hello World!" to a file called my_output.txt?
file = File.new('my_output.txt', 'w')
file.write("Hello World!")
file.close

3. What is the Directory class and what is it used for?
Dir objects represent directories in the computer's file system. They can be used to display what files that exist and what they contain.

4. What is an IO object?
An IO object that can be read and written to.

5. What is rake and what is it used for? What is a rake task?
Rake is a Ruby program for creating tasks in Ruby that can be called from the terminal or scheduled with a tool such as chron.
Loading