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

Homework for Week 7 Questions only #113

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d786dfb
First Submittion of my homework
wmuengineer Oct 20, 2013
f305b2f
Submitting Homework for week 1
wmuengineer Oct 21, 2013
aab7924
Week 2 Homework
wmuengineer Oct 22, 2013
8cd6695
First Submittion of my homework
wmuengineer Oct 20, 2013
9f5da2a
Submitting Homework for week 1
wmuengineer Oct 21, 2013
673913a
Week 2 Homework
wmuengineer Oct 22, 2013
a3be6b4
Doing a test to see if this works
wmuengineer Oct 23, 2013
e79995a
Completed calculator.rb homework
wmuengineer Oct 25, 2013
30f23e0
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
wmuengineer Oct 25, 2013
e3a1a27
Calculation.rb is complete
wmuengineer Oct 25, 2013
1382d17
Merge branch 'master' of https://github.com/wmuengineer/RubyFall2013
wmuengineer Oct 28, 2013
4ecf01e
Commit to fix merge issues.
wmuengineer Oct 28, 2013
485cf44
in class comments
wmuengineer Oct 30, 2013
c3c88b0
merging like changes
wmuengineer Oct 31, 2013
27789a6
Submiting Homework 4
wmuengineer Nov 5, 2013
6134474
hi
wmuengineer Nov 8, 2013
c41bf1d
This is an attempt to pull down changes for class.
wmuengineer Nov 8, 2013
f5096e5
Commiting homework
wmuengineer Nov 20, 2013
4922a41
ji
wmuengineer Nov 20, 2013
d370a44
Commit to make sure things are updating properly.
wmuengineer Nov 25, 2013
98de6bc
Only the questions this week.
wmuengineer Nov 26, 2013
1bee753
Working on final
wmuengineer Dec 6, 2013
02db76a
Added initial player functionality, board, and game locations.
wmuengineer Dec 8, 2013
acd67e7
Making load of progress, Working on getting the player inputs to work…
wmuengineer Dec 9, 2013
4ac1ce0
Added current_state method.
wmuengineer Dec 10, 2013
147d59c
adding functionality to determine winner
wmuengineer Dec 10, 2013
32bbc70
All test are passing.
wmuengineer Dec 10, 2013
ca3f105
Final commit
wmuengineer Dec 10, 2013
7a908b3
Final Commit
wmuengineer Dec 11, 2013
75c41bd
Delete Final exam.sublime-project
wmuengineer Dec 11, 2013
a6db8fc
Delete Final exam.sublime-workspace
wmuengineer Dec 11, 2013
a4813ad
Delete untitled.rb
wmuengineer Dec 11, 2013
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

week2/homework/simon_says.rb
Empty file added midterm/untitled.rb
Empty file.
59 changes: 59 additions & 0 deletions untitled.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>documents</key>
<array>
<dict>
<key>filename</key>
<string>week2/exercises/book_spec.rb</string>
<key>lastUsed</key>
<date>2013-10-23T03:01:38Z</date>
</dict>
<dict>
<key>filename</key>
<string>week3/exercises/monster.rb</string>
</dict>
<dict>
<key>filename</key>
<string>week3/exercises/monsters.rb</string>
<key>lastUsed</key>
<date>2013-10-23T03:28:51Z</date>
<key>selected</key>
<true/>
</dict>
<dict>
<key>filename</key>
<string>week3/exercises/named_thing.rb</string>
</dict>
<dict>
<key>filename</key>
<string>week3/exercises/vampire.rb</string>
</dict>
<dict>
<key>filename</key>
<string>week2/exercises/book.rb</string>
<key>lastUsed</key>
<date>2013-10-23T03:01:40Z</date>
</dict>
<dict>
<key>filename</key>
<string>week2/exercises/mad_libs.rb</string>
</dict>
<dict>
<key>filename</key>
<string>week2/homework/simon_says.rb</string>
<key>lastUsed</key>
<date>2013-10-23T01:32:06Z</date>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
<integer>200</integer>
<key>metaData</key>
<dict/>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{210, 54}, {1070, 719}}</string>
</dict>
</plist>
14 changes: 9 additions & 5 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ Please read:
Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
1. What is an object?- Everything in Ruby is an object.

2. What is a variable?
2. What is a variable? something i can manipulate/change

3. What is the difference between an object and a class?
3. What is the difference between an object and a class? A class is an object that represents a state and methods that can change that state.

4. What is a String?
4. What is a String? text

5. What are three messages that I can send to a string object? Hint: think methods
length, new concatenate

6. What are two ways of defining a String literal?
Single quotes : is a what you see is what you get.
double quotes : The string can use string interpolation to allow you to enter text dynamically" "

6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
12 changes: 12 additions & 0 deletions week1/homework/string-program.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# def initialize (my_string)
my_string = "Renée is a fun teacher. Ruby is a really cool programming language"
puts "#{my_string}"
# end
#def text_ops (text)
s_length = my_string.length
split_string = my_string.split(".")
puts "#{s_length}"
puts "#{split_string}"
# end
#end
11 changes: 7 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,17 @@
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.should_not be_nil
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
Binary file modified week2/.DS_Store
Binary file not shown.
16 changes: 15 additions & 1 deletion week2/exercises/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class Book

@@book_count = 0

<<<<<<< HEAD
def self.library_count
@@book_count
end

def test
@test= "hello!"
=======
def self.book_count
@@book_count
end
Expand All @@ -17,11 +25,17 @@ def initialize title = "Not Set", page_count = 0

def test
@test = "Hello!"
>>>>>>> fde8a74b427aa79cd14a4014401682c12225e82b
end

def out_put_test
puts @test
puts @@book_count
end
<<<<<<< HEAD
end

=======

end
end
>>>>>>> fde8a74b427aa79cd14a4014401682c12225e82b
32 changes: 31 additions & 1 deletion week2/exercises/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
require './book'

describe Book do
<<<<<<< HEAD

context "::new" do
it ""

end


context "title" do

before :each do

@book = Book.new("Harry Potter", 200)
end
it "should respond to title" do
@book.should respond_to "title"
end
it "shoud be able to set " do
@book.title = "Good to Great"
@book.title.should eq "Good to Great"
end

it "should return the page count" do
@book.page_count.should eq "Page count is 200"
end
end
end

=======


context "::book_count" do
Expand Down Expand Up @@ -46,4 +75,5 @@

end

end
end
>>>>>>> fde8a74b427aa79cd14a4014401682c12225e82b
19 changes: 17 additions & 2 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
An array stores data using an index as the locator. A Hash uses a key that can be any object. That object is associated with the data stored under that key.

2. When would you use an Array over a Hash and vice versa?

3. What is a module? Enumerable is a built in Ruby module, what is it?
An array seems to be a good idea when you're intaking data for processing. In the example in the book when you want to do a word counting operation, creating a large array with all of the words as entries seems like a good idea. Now when that array is read each word can serve as a key and you can count how many times that word appears.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
Another place i can see an array having short coming is if I were to design an application with custom fields. If i were to use an array i would have to "keep track" of the data to know what to report back as an answer to a query. If all of the entries are hashes I just retrieve the data based on the hash.

3. What is a module?
A module is a collection of classes, methods and constants that can be used together.

Enumerable is a built in Ruby module, what is it?

Emumerable is a mixin that allows your class to use methods that aid in sorting, comparing and modifying hashes and arrays.

4. Can you inherit more than one thing in Ruby?
No Ruby is a single inheritance language.

How could you get around this problem?
Mixins/modules help get around this problem by providing inheritance like functionality.

5. What is the difference between a Module and a Class?
A class contains methods and constants. A module can contain classes, methods, and constants. Modules help prevent clashed between methods with the same names between different classes.
2 changes: 1 addition & 1 deletion week2/homework/simon_says_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
end

it "should repeat" do
repeat("hello").should == "hello hello"
repeat("hello", 2).should == "hello hello"
end

it "should repeat a number of times" do
Expand Down
18 changes: 18 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Calculator
def sum input
input.reduce(:+).to_f # Class notes ( result = 0, input.each do |i| result +=1
end

def multiply a, b=1 # *(args or input)
[a, b].flatten.reduce(:*).to_f
end

def fac a
(1..(a.zero? ? 1 : a)).inject(:*) # 1.upto()
end

def pow a, b
a**b
end

end
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -28,11 +28,11 @@
# write tests and code for the following:
describe "#multiply" do
it "multiplies two numbers" do
@calculator.multiply(2,2).should eq 4
@calculator.multiply(7,2).should eq 14
end

it "multiplies an array of numbers" do
@calculator.multiply([2,2]).should eq 4
@calculator.multiply([2,7]).should eq 14
end
end

Expand Down
8 changes: 8 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ Please Read:

1. What is a symbol?

An identifier cooresponding to a string.

2. What is the difference between a symbol and a string?

A string is just a "string". A symbol is a string serves the purpose of identifying an object.

3. What is a block and how do I call a block?

A set of code that is inside {} or the keywords do and end. A block can be thought of as a method itself that is called a yield statement.

4. How do I pass a block to a method? What is the method signature?
Be defining a method that used yield to invoke the code inside the block when that method is used. The method signature is the name of the method.

5. Where would you use regular expressions?
To sort through various strings searching for patterns.
10 changes: 10 additions & 0 deletions week4/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
task :default => [:hello_world]

desc "this outputs hello world!"
task :hello_world do
puts "hello world!"
end

def test
"tequila"
end
19 changes: 19 additions & 0 deletions week4/class_materials/class_power.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class PowerOfTwo
attr_reader :value

def initialize(value)
@value = value
end

def <=>(other)
@value <=> other.value
end

def succ
PowerOfTwo.new(@value + @value)
end

def to_s
@value.to_s
end
end
5 changes: 5 additions & 0 deletions week4/class_materials/untitled.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@





9 changes: 9 additions & 0 deletions week4/code_timer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CodeTimer
def time_code
start_time = Time.now
yield
Time.now - start_time

end

end
2 changes: 2 additions & 0 deletions week4/filemaker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
File.open("output.txt", "w") { |file| file.puts "Hello"
file.puts "1 + 2 = #{1+2}" }
Empty file added week4/homework/my_output.txt
Empty file.
6 changes: 6 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
Ruby uses the IO base class to handle all input and output. A sub class called file provides the tools for reading files. the method gets can be used to read lines of a file.
2. How would you output "Hello World!" to a file called my_output.txt?
File.open("my_output.txt", "w") { |file| file.puts "Hello world }
3. What is the Directory class and what is it used for?
The directory class contains methods used to list diretories in the file system.
4. What is an IO object?
A bidirectional channel between ruby and the "outside world".

5. What is rake and what is it used for? What is a rake task?
Rake must be a package written in ruby that helps run tests on the code that we are developing. You can run a task called unit test or default. I'm also thinking you can run rake db:migrate. So rake must be the task executer for ruby.
15 changes: 15 additions & 0 deletions week4/homework/work.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Worker
def self.work a=0
(a.zero? ? yield : (a-1).times {yield } ) # inject can replace this.
#(a-1).times {|input| yield}
yield

#class solution
n.times.inject(nil){|results, i| yield}
n.times.inject(nil){ yield }

# inject needs a starting variable [0].inject{|results, i| puts i }
# this outputs zero as the inject module doesn't run the block next to it if it don't have a initial value.

end
end
Loading