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

week 7 homework #106

Open
wants to merge 15 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
7 changes: 7 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
Everything in ruby is an object, it's a piece of data that can be manipulated or hold properties.

2. What is a variable?
A variable is name that is assigned to reference a piece of information to be called on later.

3. What is the difference between an object and a class?
A class is a definition for objects in it, it defines object properties. An object is an instance of a class.

4. What is a String?
A sequence of characters.

5. What are three messages that I can send to a string object? Hint: think methods
upcase, reverse, capitalize

6. What are two ways of defining a String literal? Bonus: What is the difference between them?
Using quotes or %.

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 charaters" do
@my_string.length.should eq(66)
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.to_s.should eq("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?
You index arrays with integers, and index a hash with objects.

2. When would you use an Array over a Hash and vice versa?
Arrays are good for storing large sets of data with only 1 value, say like a list of names. A hash would be good for storing a set of data that would include more information about those 50 people, like their address and birthdate. You can then put the hashes into an array.

3. What is a module? Enumerable is a built in Ruby module, what is it?
A sort of library for methods and constants. Enumerable is a mixin that provides searching and sorting methods.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
No, ruby is a single inheritance language. You can get around this problem using mixins.

5. What is the difference between a Module and a Class?
A class is a collection of objects, a module is a collection of functions.
25 changes: 25 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module SimonSays


def echo(word)
word
end

def shout(word)
word.upcase
end

def repeat(word, n = 2)
( "#{word} " * n ).strip
end

def start_of_word(word, n)
word[0,n]
end

def first_word(string)
string.split[0]
end


end
32 changes: 32 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Calculator


def new
initialize
end


def sum(array)
array.inject(:+).to_i
end


def multiply(*array)
array.flatten!
array.inject(:*)

end

def pow(num,exp)
num ** exp
end

def fac(n)
if n == 0
return 1
end
else
n.downto(1).inject(:*)
end

end
2 changes: 1 addition & 1 deletion week3/homework/calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "#{File.dirname(__FILE__)}/calculator"
require "./calculator.rb"

describe Calculator do

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

1. What is a symbol?
A Ruby symbol is an identifier corresponding to a string of characters, often a name. Example: :symbol

2. What is the difference between a symbol and a string?
Symbols are not mutable, or changeable. Symbols also remain in memory while program is in operation, each new instance does not require additional memory / object ID.

3. What is a block and how do I call a block?
A block is a chunk of goes between braces or "do" and "end." Blocks are called my invoking a method.

4. How do I pass a block to a method? What is the method signature?
Each or yield are examples. "each &block"

5. Where would you use regular expressions?
When you are trying to do pattern matching or text processing.
9 changes: 8 additions & 1 deletion week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
What I gleamed from the book is that basically it reads line by line from the object file, using the File.gets

2. How would you output "Hello World!" to a file called my_output.txt?
File.open("my_output.txt", "w")
File.puts "Hello world!"
File.close

3. What is the Directory class and what is it used for?
It contains objects that represent directories in a file system, the class is used for modifying, searching for, and listing files/directories.

4. What is an IO object?
An IO object is a bidirectional channel between a Ruby program and some external
resource. Something you read from and write to.

5. What is rake and what is it used for? What is a rake task?

It's a build tool used to create and manage tasks, sort of like automating things? Nothing I've read has been exactly clear as to what a rake task is, but from what I have gathered it's a task that runs according to the rules and parameters you set in the RakeFile? Need this to be explained.
14 changes: 14 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Worker

def self.work(n=0)
result = nil
if n > 0
n.times{ |stuff| result = yield(stuff) }
result
else
result = yield
end

end

end
2 changes: 2 additions & 0 deletions week7/homework/PirateTranslator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PirateTranslator
end
12 changes: 12 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PirateTranslator

def say(words)
@words = words
end

def translate
@words.gsub(/\w/, "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!")
end


end
4 changes: 4 additions & 0 deletions week7/homework/features/step_definitions/pirate_speak.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PirateTranslator


end
Loading