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

DougM tic-tac-toe submission for final #118

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a3d3aba
Added info for number 17
Doug-MacDowell Oct 11, 2013
eb43242
Homework submission
Doug-MacDowell Oct 14, 2013
66ca065
temp file
Doug-MacDowell Oct 16, 2013
3cea7d1
a comment
Doug-MacDowell Oct 16, 2013
62b40ca
week 2 material
Doug-MacDowell Oct 16, 2013
7cfc148
Homework complete for week 2
Doug-MacDowell Oct 22, 2013
f6936f6
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Oct 22, 2013
85f56ea
Week 3 homework submission
Doug-MacDowell Oct 29, 2013
cb7524a
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Oct 30, 2013
8b55bb6
Week 4 homework answers from Doug M
Doug-MacDowell Nov 6, 2013
b6e457e
Week 4 worker file submission for spec
Doug-MacDowell Nov 6, 2013
36e367a
This file appears to have not been committed in Week 2
Doug-MacDowell Nov 6, 2013
6198eb0
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Nov 6, 2013
2d476c0
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Nov 8, 2013
b31602e
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Nov 13, 2013
267f1e1
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Nov 20, 2013
262f033
DougM homework for week 7
Doug-MacDowell Nov 27, 2013
837425f
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Nov 27, 2013
21113f2
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Doug-MacDowell Dec 4, 2013
fce2aef
Initial commit
Doug-MacDowell Dec 6, 2013
e214aa6
renamed the file to match others in project
Doug-MacDowell Dec 7, 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
14 changes: 10 additions & 4 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ 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?
A: Basically, everything you manipulate in Ruby is an object, and the results of these manipulations are objects as well.

2. What is a variable?
2. What is a variable?
A: Variables are used to keep track of objects. They provide a reference to an object.

3. What is the difference between an object and a class?
3. What is the difference between an object and a class?
A: Objects begin as instances of classes. A class is a collection of characteristics and functionality and serves as a blueprint from which an object is created.

4. What is a String?
4. What is a String?
A: In Ruby, strings are sequences of characters. They are objects of the class String.

5. What are three messages that I can send to a string object? Hint: think methods
A: Three common messages are scan, split, and squeeze.

6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
A: A String literal can be defined by single quotes and by double quotes. The use of double quotes provides many more options for escape sequences and allows you to substitute the value of Ruby code into the string.
20 changes: 12 additions & 8 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@

describe String do
context "When a string is defined" do
before(:all) do
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 split on the . charater" do
pending
result = #do something with @my_string here

it "should be able to count the characters" do
expect(@my_string.length).to eq(66)
end

it "should be able to split on the . character" do
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"))'
# pending 'helpful hint: should eq (Encoding.find("UTF-8"))'
(@my_string.encoding).should eq (Encoding.find("UTF-8"))
end
end
end

end
11 changes: 11 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ Please Read The Chapters on:
Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

Submitted by: Doug MacDowell

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

A. Both hashes and arrays are similar in that they hold a collection of object references. The difference is in how the object references are identified. In arrays, the position of the object reference is identified by a non-negative integer index, while in a hash, the object reference can be indexed with objects of any type, such as symbols or strings, etc.

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

A. An array is more suited for storing items that do not need to be returned in a specific order. With hashes, Ruby remembers the order in which items are added to the hash, and when iterating over these items, Ruby generally returns them in order.

3. What is a module? Enumerable is a built in Ruby module, what is it?

A. A module is a collection of methods and constants, as well as classes. The Enumerable module is a mixin that provides collection classes with methods that can traverse, search, and sort the members of the collection.

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

A. Yes. To get around this, we should design using compositional relationships, rather than strict, tightly-coupled hierarchies.

5. What is the difference between a Module and a Class?
A. A module is basically a class that cannot be instantiated. And unlike a class, a module can be used to group items together that don't naturally form a class, by the use of a namespace to segregate diverse methods and constants. A class inherits behavior, while there is no inheritance in modules. Modules can provide functionality across multiple classes, whereas a class is more object-centric.
31 changes: 31 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module SimonSays

attr_reader :the_string

def initialize
@the_string = the_string
end

def echo the_string
the_string
end

def shout(the_string)
the_string.upcase
end

def repeat(the_string, the_count=2)
a = Array.new(the_count, the_string)
a.join ' '
end

def start_of_word(the_string, n)
letters = n - 1
the_string.slice(0..letters)
end

def first_word(the_string)
the_string.split[0..0].join(' ')
end

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

def pow(val1, val2)
val1**val2
end

def sum(the_input)
the_sum = 0
the_input.each do |value|
the_sum += value
end
return the_sum
end

def fac(x)
(1..(x.zero? ? 1 : x)).inject(:*)
end

# the version below works for multiple values and arrays
def multiply(*input)
input.flatten.inject(:*)
end

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

1. What is a symbol?

A. A symbol is an identifier corresponding to a string of characters, often a name. Symbol objects are constructed using by preceding the name with a colon. Arbitrary strings can be symbolized by preceding the string literal with a colon.

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

A. A symbol is actually a string, but the difference is that a symbol is immutable. That is, unlike a string, a symbol can be overwritten but not changed. The receiver methods we can use on strings won't work with a symbol.

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

A. A block is basically a chunk of Ruby code that can be associated with method invocations. The code in the block is not executed as it is encountered, but Ruby instead remembers the context in which the block appears and then enters the associated method. Blocks consist of code that runs under some sort of transactional control.

A block is called when associated with a method. The content of a block can be placed between braces, or between a "do" and "end". A block may also be invoked within a method by using the "yield" statement.

4. How do I pass a block to a method? What is the method signature?

A. When executing a method, you can add a block of code by surrounding the block in braces. An iterator method can also target and invoke a block.

A method signature defines the number and order in which arguments are to be passed into the method.

5. Where would you use regular expressions?

A. Regular expressions are useful when working with strings. There are times when the Ruby String class does not support what is needed in practice, such as testing for pattern matches, searching and replacing specific pieces of a string, or extracting particular parts of a string. These are tasks that regular expressions are designed for.
15 changes: 15 additions & 0 deletions week4/exercises/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Worker

# this only works for one block execution
#
# def self.work
# yield
# end
#
# this works for all blocks in this exercise
#
def self.work(count = 1)
(0..count).inject {yield}
end

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

1. How does Ruby read files?
A. Ruby has a base class called IO that is subclassed by the File class. IO objects are able to be read (and written) between Ruby and the file.

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

3. What is the Directory class and what is it used for?
A. Objects in this class are directory streams that represent the directories of a file system. This class is used mainly to list the directories and their content.

4. What is an IO object?
A. An IO object is a bidirectional communications channel between a Ruby program and some external resource, such as a file.

5. What is rake and what is it used for? What is a rake task?
A. Rake is a Ruby build program, similar to "make". It is used for building rakefiles using Ruby syntax, and has a library of prepackaged tasks that perform operations like building tarballs or publishing to FTP.

A rake task is a basic unit of work in a rakefile. Rake tasks have both actions and a list of prerequisites to check before taking an action.
11 changes: 11 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PirateTranslator

def initialize
@reply = "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!"
end

def send(*arg)
@result = @reply
end

end
9 changes: 9 additions & 0 deletions week7/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming

Questions:
1. What is method_missing and how can it be used?
A. This is a hook method that Ruby will try to invoke on an object when a method call is made and Ruby can't find the method in the object's class or superclasses. It can be used to intercept and handle (or report) undefined methods, or it can be used with patterns to selectively forward particular method calls to a superclass.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good.


2. What is and Eigenclass and what is it used for? Where Do Singleton methods live?
A. An Eigenclass is a dynamically created anonymous class that holds an object's singleton methods. It is used when you need Ruby to find the object's singleton methods without disrupting the method lookup path. Singleton methods are defined on the objects themselves, rather than in its class, therefore they are dynamic.

3. When would you use DuckTypeing? How would you use it to improve your code?
A. Duck Typing is a useful technique in situations where you want flexibility, without having to check the type of the arguments, which generally doesn't add any value. Code is improved and more flexible when you don't have to include checks on the argument types.

4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval?
A. A class method is defined within a class and the method can be used in any subclasses of that class. Instance methods are created in a module and are available as instance methods of the class that includes the module. class_eval sets things up as if you were within a class definition. Any method definitions created there define instance methods. Calling instance_eval on a class differs because method definitions created there are class methods.

5. What is the difference between a singleton class and a singleton method?
A. A singleton method is a method that is specific to a particular object, while a singleton class is an anonymous class that Ruby creates when defining a singleton method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent.