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

Homework questions completed - KK #109

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4dc5fc4
Update roster.txt
kirrk Oct 9, 2013
e03b470
First Commit
kirrk Oct 11, 2013
6793e56
First Commit
kirrk Oct 11, 2013
f63b477
Update questions.txt
kirrk Oct 13, 2013
26972ec
Update strings_and_rspec_spec.rb
kirrk Oct 13, 2013
02b1e21
Update strings_and_rspec_spec.rb
kirrk Oct 14, 2013
c37e79c
Update strings_and_rspec_spec.rb
kirrk Oct 15, 2013
8bc7c89
Update strings_and_rspec_spec.rb
kirrk Oct 15, 2013
4962306
changes for rspec strings
kirrk Oct 15, 2013
b8440c9
Update strings_and_rspec_spec.rb
kirrk Oct 15, 2013
f96bd55
updates to homework
kirrk Oct 15, 2013
348bd9b
all files updated
kirrk Oct 16, 2013
b9b6832
m
kirrk Oct 16, 2013
08ad326
homework week 2 completed
kirrk Oct 22, 2013
09b58b6
completed homework week 2
kirrk Oct 22, 2013
be06c59
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Oct 23, 2013
c11fe41
homework questions complete
kirrk Oct 27, 2013
5acd3bb
completed homework
kirrk Oct 29, 2013
7ab4c2f
class updates
kirrk Oct 30, 2013
c8ed324
updated exercise files
kirrk Oct 30, 2013
87943bb
updated per class review
kirrk Oct 30, 2013
2d4c35f
updated
kirrk Nov 5, 2013
e5108e3
completed homework
kirrk Nov 5, 2013
01eb78c
completed hw
kirrk Nov 6, 2013
2d44823
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Nov 6, 2013
9b7e61e
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Nov 9, 2013
0cdc008
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Nov 16, 2013
7e05220
add week 6
kirrk Nov 16, 2013
ee472bf
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Nov 20, 2013
3d2eeaa
update questions
kirrk Nov 25, 2013
8f8cab7
update questions
kirrk Nov 25, 2013
1f72756
update questions
kirrk Nov 26, 2013
515c33c
complete hw questions
kirrk Nov 26, 2013
f7404eb
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Nov 27, 2013
021ee5d
update hw
kirrk Nov 27, 2013
032b64d
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk Dec 4, 2013
5dc2698
update branch
kirrk Dec 4, 2013
8f20ef6
got a little confused on the steps
kirrk Dec 10, 2013
84c8f46
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
kirrk 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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Karen
Submodule Karen added at 2a1c91
3 changes: 3 additions & 0 deletions midterm/instructions_and_questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Instructions for Mid-Term submission and Git Review (10pts):

Questions (20pts):
- What are the three uses of the curly brackets {} in Ruby?
Three uses are: Curly brackets can replace 'do' and 'end'; they represent the beginning and end of a block
They represent a placeholder for data being held by a variable (i.e., #{})

- What is a regular expression and what is a common use for them?
- What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby?
- Are these two statements equivalent? Why or Why Not?
Expand Down
Empty file added midterm/turkey.rb
Empty file.
8 changes: 8 additions & 0 deletions midterm/wish_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class WishList
def wishes
arraywish = ["Lamborghini", "Corn Starch and Water Moat", "Vegan Bacon Ice Cream", "Rubber Chicken", "Free Tickets to Ender's Game"]
en
arrayWish.map { |e| e, puts e }
end

end
3 changes: 3 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
put "sdflkjsldf" |do|

end
Binary file added week1/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?

Objects are instances of a class. An object is defined by a class. A class is a blueprint from which individual objects are created. You typically define methods that let you access and manipulate the state of an object.

2. What is a variable?
There are several different types of variables in Ruby:
Local Variable
Instance Variale
Global variable
Constant

In general, a variable will vary or change, it is not fixed.

3. What is the difference between an object and a class?
An object is an instance of a class, while a class is a blueprint from which individual objects are created.

4. What is a String?
Ruby strings are sequences of characters. They normally hold printable characters. Strings are objects of class String.
Strings are often created using string literals - sequences of characters between delimiters.

5. What are three messages that I can send to a string object? Hint: think methods
a statement, expression, here documents

6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
14 changes: 10 additions & 4 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#using ARGV
# encoding: utf-8

# Please make these examples all pass
Expand All @@ -14,13 +15,18 @@
end
it "should be able to count the charaters"
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here


result = str.count(@my_string)
result2 = @my_string.split(".")
result.should have(2).items
return result + " " + result2
end
it "should be able to give the encoding of the string" do
pending 'helpful hint: should eq (Encoding.find("UTF-8"))'

encoderesult = @my_string.encoding
encoderesult.encoding
encoderesult should eq Encoding.find("UTF-8")
end
end
end

9 changes: 8 additions & 1 deletion week2/exercises/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ class Book

@@book_count = 0

<<<<<<< HEAD
def initialize (title, pages)
@title = title
@pages = pages
end
=======
def self.book_count
@@book_count
end
>>>>>>> e040d45f81ce3c4ddfed6debf5b753b82d0e59f7

def initialize title = "Not Set", page_count = 0
@@book_count += 1
Expand All @@ -24,4 +31,4 @@ def out_put_test
puts @@book_count
end

end
end
34 changes: 34 additions & 0 deletions week2/exercises/book.rb.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Book
attr_accessor :title
attr_reader :page_count

@@book_count = 0

<<<<<<< HEAD
def initialize (title, pages)
@title = title
@pages = pages
end
=======
def self.book_count
@@book_count
end
>>>>>>> e040d45f81ce3c4ddfed6debf5b753b82d0e59f7

def initialize title = "Not Set", page_count = 0
@@book_count += 1
@page_count = page_count
@title = title
end


def test
@test = "Hello!"
end

def out_put_test
puts @test
puts @@book_count
end

end
33 changes: 32 additions & 1 deletion week2/exercises/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@

describe Book do

<<<<<<< HEAD
# context "::new" do

#it "should set some defaults" do
# Book.new.title.should eq "Not Set"
#end
#end

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

before :each do
@book = Book.new("Harry Potter", 200)
end
it "should respond to title" do
@book.should respond_to "title"
end

#context "#title" do

#it "should allow me to set the title" do
# @book.title = "Snow Crash"
# @book.title should eq "Snow Crash"
# end

#end

end
=======

context "::book_count" do

Expand Down Expand Up @@ -46,4 +76,5 @@

end

end
end
>>>>>>> e040d45f81ce3c4ddfed6debf5b753b82d0e59f7
80 changes: 80 additions & 0 deletions week2/exercises/book_spec.rb.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require './book'

describe Book do

<<<<<<< HEAD
# context "::new" do

#it "should set some defaults" do
# Book.new.title.should eq "Not Set"
#end
#end

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

before :each do
@book = Book.new("Harry Potter", 200)
end
it "should respond to title" do
@book.should respond_to "title"
end

#context "#title" do

#it "should allow me to set the title" do
# @book.title = "Snow Crash"
# @book.title should eq "Snow Crash"
# end

#end

end
=======

context "::book_count" do

it "should count how many books have been created" do
Book.new
Book.new
Book.new
Book.book_count.should eq 3
end

end

context "::new" do

it "should set some defaults" do
Book.new.title.should eq "Not Set"
end

it "should allow us to set the page count" do
book = Book.new "Harry Potter", 5
book.page_count.should eq 5
end

end

context "#title" do

before :each do
@book = Book.new
end

it "should have a title" do
@book.should respond_to "title"
end

it "should allow me to set the title" do
@book.title = "Snow Crash"
@book.title.should eq "Snow Crash"
end



end

end
>>>>>>> e040d45f81ce3c4ddfed6debf5b753b82d0e59f7
54 changes: 42 additions & 12 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
Please Read The Chapters on:
Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins
Please Read The Chapters on:
Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
Arrays are ordered, integer-indexed collections of any object. Each object reference occupies a position in the array, identified by a non-negative integer-index. Hashes, like arrays, are indexed collections of object references; however, while arrays are indexed with integers, you index a hash with objects of any type: symbols, strings, regular expressions etc.
When storing a value in a hash, you store the key and the entry to be stored with the key.

2. When would you use an Array over a Hash and vice versa?
An example re: when you would use a hash would be: If you wanted to map musical instruments to their orchestral sections, you would use a hash:

instSection = {
'cello' => 'string',
'clarinet' => 'woodwind',
'drum' => 'percussion',
'oboe' => 'woodwind',
'trumpet' => 'brass',
'violin' => 'string'
}

An example re: when you would use an array would be:
If you wanted to iterate single list of items or pull them out and list them as needed, you could use an array:

a = %w{ cat dog bird lion deer}
a[0] >> "cat"
a[3] >> "lion"



3. What is a module? Enumerable is a built in Ruby module, what is it?
modules are a way of grouping together methods, classes and constants. Modules give you two major benefits:
They prevent name clashes; modules support the min facility.

modules provide a namespace, a sandbox in which methods and constants can play without being stepped on by other methods and constants. Modules essentially eliminate the need for inheritance, providing a facility called a mixin.

The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
No, multiple inheritance is not allowed in Ruby. You could get around this issue by creating a module and include it within a class. Once included within a class, you have access to all of the module's instance methods in the class as well. They get mixed in. Mixed-in modules behave as superclasses.

5. What is the difference between a Module and a Class?
While a class has instances, a module cannot. A module can't have instances because a module is not a class. However, you can include a module within a class definition.

1. What is the difference between a Hash and an Array?

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?

4. Can you inherit more than one thing in Ruby? How could you get around this problem?

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

#methods

def echo (message)
@message = message
end

def shout(message_to_shout)
@message_to_shout = message_to_shout.upcase
end

def repeat(word_to_repeat, times_to_repeat = 2)
@word_to_repeat = word_to_repeat
(@word_to_repeat + " ") * times_to_repeat
end

def start_of_word(return_letters, number_of_letters)
@return_letters = return_letters
@number_of_letters = number_of_letters
@chopped_string = return_letters.slice(0..(@number_of_letters -1))
end

def first_word(word_to_break)
@word_to_break = word_to_break
@result = @word_to_break.split
@result[0]
end

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


def sum array
# array.inject(0){|memo, n| memo + n}
array.inject(0, :+)
end

# def sum input
# result = 0
# input.each do | i |
# result += i
# end
# result

# def multiply (array_prod)
# @array_prod = array_prod
# @product = product
# @product = array_prod.inject{|memo, n| memo * 2}

# end

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

def pow (num_val, power)
num_val ** power
end

def fac(num)
(1..num).to_a.inject (:*)
end
end
Loading