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

Completed Tic-Tac-Toe #163

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions week1/exercises/moon_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe "MoonPlugin" do
context "When the moon is full" do
it "should tell us it's a full moon" do
"Renee".should include("ee")
end
end
end
2 changes: 2 additions & 0 deletions week1/exercises/roster.txt~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name, email, github, twitter, hipchat
Renee D, [email protected], reneedv, @gigglegirl4e, [email protected]
7 changes: 6 additions & 1 deletion week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@

it "should check basic spelling" do
"Field".should include('ie')
end
it "should count the characters in your name"
"Chris".should have(5).characters
it "should check basic math"

it "should check basic spelling"

end

end
24 changes: 10 additions & 14 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ Chapter 3 Classes, Objects, and Variables
p.90-94 Strings

1. What is an object?
An object is a representation in memory of a specific concept or thing that the Ruby interpreter knows about.

An object is an instantiated class.
2. What is a variable?
A variable is a name for a location in memory. It can contain, or point to, any type of object.

A variable is a reference to a stored value or object.
3. What is the difference between an object and a class?
An object is an instance of a class, or a specific thing of that class's type in memory. The class is the specifics that are common to all things of that type. The classification of a concept or a thing is a class. A specific thing or concept of a class's type in memory is an object. For example: All books have titles (Class). This book's title is "Harry Potter and the Goblet of Fire" (Object).

A class is the definition of a type of object - basically, a blueprint. Many objects can be created from
one class, that will all share the same structure and functionality, but can hold discrete states and values.
4. What is a String?
A string is how Ruby understands text. It is a collection of characters (Bytes), and can be created by making an instance of the String class (String.new) or as a string literal ("",'', %Q[]).

A string is simply a chain of characters (or... a 'string' of characters... clever). In the simplest of terms,
it is a representation of small chunks of text (or binary data).
5. What are three messages that I can send to a string object? Hint: think methods
chomp! - removes newline characters, or the specified characters, from the end of a string
strip! - removes leading or trailing whitespace from a string
split - returns an array of strings made up of the original string separated on whitespace or the specified characters or regexp

If I understand the question correctly, three string methods are Split, Scan, and Squeeze.
6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
Single quotes ex: '' and Double quotes ex: "". The single qoutes allow for 2 escape characters: \' and \\ . The double qouted string literal allows for many different escaped special characters (like \n is a line break) and allows for string interpolation, or the injection of evaluated Ruby code into the string ex: "Hello #{my_name}". The single qouted string takes up much less memory than a doulbe qouted string with interpolation. Without interpolation, both are about the same.

The two most common ways of defining a string literal are with single and double quotes. Text wrapped in single quotes
supports only the most basic escape sequence, the backslash. Double quoted text supports a wide range of escape sequences,
most notably newline characters (carriage returns).
8 changes: 5 additions & 3 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
@my_string = "Renée is a fun teacher. Ruby is a really cool programming language"
end
it "should be able to count the charaters" do
@my_string.should have(@my_string.size).characters
@my_string.should have(66).characters
end
it "should be able to split on the . charater" do
result = @my_string.split('.')
it "should be able to split on the . character" do
result = @my_string.split(".") #do something with @my_string here
result.should have(2).items
end
it "should be able to give the encoding of the string" do
puts "HERE: #{@my_string.encoding}"
@my_string.encoding.should eq (Encoding.find("UTF-8"))
#should eq (Encoding.find("UTF-8"))
end
end
end
13 changes: 13 additions & 0 deletions week2/exercises/book.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
class Book
<<<<<<< HEAD
attr_accessor :title, :page_count

def initialize(title, page_count)
@title = title
@page_count = page_count
end

def page_count
"Page count is #{@page_count}"
end
=======

attr_accessor :title, :pages

Expand All @@ -10,4 +22,5 @@ def initialize(title, pages)
def page_count
"Page count is #{@pages}"
end
>>>>>>> 476e4b543ee68aad8bb809afdfe2207afd39e8e5
end
11 changes: 11 additions & 0 deletions week2/exercises/mad_libs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
adjective = gets.chomp
puts "Please enter a past tense action verb"
verb_past_tense = gets.chomp
<<<<<<< HEAD
puts "Please enter a second noun"
noun2 = gets.chomp
puts "Please enter another adjective"
adjective2 = gets.chomp
puts "Please enter an exclamation"
exclamation = gets.chomp.upcase

story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard. The #{noun} spotted a #{adjective2} #{noun2}, and yelled '#{exclamation}!'"
=======
puts "What does the #{noun} say?"
says = gets.chomp
story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}"
>>>>>>> 476e4b543ee68aad8bb809afdfe2207afd39e8e5
puts story
35 changes: 27 additions & 8 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
An array is an ordered list of items that are referenced by their index (order), a hash is a collection of items that can be referenced by a key and have no order.

They are very similar, in that they are both collections of objects, but an array can only be indexed
by an integer, while a hash can be indexed by any object (similar to an associative array in other languages,
but even more flexible - the key is not limited to just strings).

2. When would you use an Array over a Hash and vice versa?
When the items have an inherent order I would use an array, when I want to reference the items in my collection by a name or key and their order does not matter I would use a hash.

An array is very useful for building queues, as it logically lends itself well to working with ordering
and numbered positions within a collection. There is an obvious relationship between the index and
the logic of the situation. However, the flexibility of indexing in a has allows you to be more descriptive
or complex in your implementation of the collection - you can use a simple string to name values, or
go more complex and use an object as the key (although this might require implementing your own methods
for testing equality.)

3. What is a module? Enumerable is a built in Ruby module, what is it?
A module is a way to group code that you can use across multiple classes. Enumerable is a Ruby module that provides collection functionality; iteration, searching, and sorting. It requires an implementation of the each method.

A module is a collection of functionality under a common namespace. It is similar in concept to defining
some methods within a file, and including that file within another script, but with the added benefit
of preventing name collisions between different methods, which could easily occur with the file
inclusion method.

Enumerable is, as stated, a module. It is used as a mixin for any collection class to provide it with
traversal and sorting functionality, given the host class provides implementations of a couple of basic sorting
and comparison methods. (e.g., the <=> method)

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 can include multiple modules if you wanted to mix-in different functionality into your code. Code that is related with a hierarchical nature should be subclassed (inherited). A class can only have 1 direct parent, but can have lots of ancestors.
Ruby does not support multiple inheritance - however, if you require centralized functionality to be shared
between different classes, you can define it inside a module, and include that module within the different
classes (which is called a mixin).

5. What is the difference between a Module and a Class?
A class can be instantiated into an object, a module cannot. A module is code that can be used across many classes.
A class can be instantiated, while a module cannot. They are both good ways of collecting reusable
logic, but a class is best suited to representing some sort of logical object (serving as a blueprint),
whereas a module can be seen as a sort of library - simply a collection of functionality that can be included
where it is needed (and provide the benefits of multiple inheritance, without the downsides!)
23 changes: 23 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
module SimonSays
<<<<<<< HEAD
def echo(input)
input
end

def shout(input)
input.upcase
end

def repeat(input, num_of_repeats = 2)
((input + " ") * num_of_repeats).strip
end

def start_of_word(input, num_of_characters = 1)
input[0...num_of_characters]
end

def first_word(input)
input.split[0]
end
=======
def echo(st)
st
end
Expand All @@ -19,4 +40,6 @@ def repeat(st, t=2)
return "Go Away!" if t==0
([st]*t).join(' ')
end
>>>>>>> 217a9fddb9c3593e5125cdc0b20bbd32afab6597
end

2 changes: 1 addition & 1 deletion week3/exercises/monster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class Monster
include NamedThing
attr_accessor :vulnerabilities, :dangers
attr_reader :nocturnal, :legs
attr_reader :nocturnal, :legs

def initialize(noc, legs, name="Monster", vul = [], dangers = [])
super(name)
Expand Down
28 changes: 28 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
class Calculator
<<<<<<< HEAD

def sum(input)
output = 0
input.each { |element| output += element }
output
end

def multiply(input)
output = 1 #since multiplying by zero always equals zero
input.each { |element| output = output * element }
output
end

def toThePowerOf(input, exponent)
input **= exponent
end

def factorial(input)
output = 1
for i in 1..input do
output *= i
end
output
end
end
=======
def sum(array)
array.inject(0){|sum, x| sum +x}
end
Expand All @@ -22,3 +49,4 @@ def pow_fac(base=nil, p)
(1..p).to_a.inject(1){|f,v| f *= base || v}
end
end
>>>>>>> 217a9fddb9c3593e5125cdc0b20bbd32afab6597
35 changes: 35 additions & 0 deletions week3/homework/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
# Once the above tests pass,
# write tests and code for the following:
describe "#multiply" do
<<<<<<< HEAD
it "multiplies two numbers" do
@calculator.multiply([2,3]).should == 6
end

it "multiplies an array of numbers" do
@calculator.multiply([2, 3, 5]).should == 30
end
end

describe "#toThePowerOf" do
it "raises one number to the power of another number" do
@calculator.toThePowerOf(2, 4).should == 16
end
end

# http://en.wikipedia.org/wiki/Factorial
describe "#factorial" do
it "computes the factorial of 0" do
@calculator.factorial(0).should == 1
end
it "computes the factorial of 1" do
@calculator.factorial(1).should == 1
end
it "computes the factorial of 2" do
@calculator.factorial(2).should == 2
end
it "computes the factorial of 5" do
@calculator.factorial(5).should == 120
end
it "computes the factorial of 10" do
@calculator.factorial(10).should == 3628800
end
=======
it "multiplies two numbers" do
@calculator.multiply(2,2).should eq 4
end
Expand Down Expand Up @@ -63,6 +97,7 @@
@calculator.fac(10).should eq 3628800
end

>>>>>>> 217a9fddb9c3593e5125cdc0b20bbd32afab6597
end

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

1. What is a symbol?
<<<<<<< HEAD
A symbol is superficially similar to a string, but in reality is a constant and immutable
object. They are useful as names and identifiers, and commonly serve as hash keys.
2. What is the difference between a symbol and a string?
Strings can be modified, and multiple string objects can have the same contents and still be
different objects. Symbols, however, cannot be modified ( like a frozen string in this regard), and
the same symbol always refers to the same object. :test and :test have the same object ID, while
"test" and "test" would not.
3. What is a block and how do I call a block?
A block is an arbitrary chunk of Ruby code that can be supplied to an existing method call. It is called
by using a do-end following a method call(or curly brackets if the block is only one line)
4. How do I pass a block to a method? What is the method signature?
The method itself must be written to account for blocks - either by testing for the presence of a
supplied block and changing its flow based upon the result, or by being written to always expect
a block. At the point of method execution where the block should be started, it can be called
with the Yield signature and the appropriate number of arguments.
5. Where would you use regular expressions?
Regular expressions are useful for input parsing (e.g., ensuring a supplied email address is a valid
one). They can be used to strip undesirable characters from a string, or search a block of text
to find any instances of a search term.
=======
A symbol is a static name or identifier.

2. What is the difference between a symbol and a string?
Expand All @@ -15,6 +36,7 @@ A block is an anonymous function, or some code snipt that you can define and the

4. How do I pass a block to a method? What is the method signature?
To pass a block to a method you define the block after the method call with either the curly bracket enclosure {} or the do/end syntax. An example of passing a block to the each method of an array:
>>>>>>> 217a9fddb9c3593e5125cdc0b20bbd32afab6597

my_array.each {|a| puts a}

Expand Down
14 changes: 12 additions & 2 deletions week5/exercises/Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
task :test do
puts "Hello World!"
config = {:basedirectory => "class"}

task :makeclassdirectory do
Dir.mkdir(config[:basedirectory]) unless File.exists?(config[:basedirectory])
end

task :classmaker => ["makeclassdirectory"] do
File.open("names", "r") do |file|
file.each do |line|
Dir.mkdir(config[:basedirectory].to_s + "/" + line.chomp!) unless File.exists?(config[:basedirectory].to_s + "/" + line.chomp!)
end
end
end

task :make_class_dir do
Expand Down
5 changes: 5 additions & 0 deletions week5/exercises/classmaker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File.open("names", "r") do |file|
file.each do |line|
Dir.mkdir(line.chomp!)
end
end
1 change: 1 addition & 0 deletions week6/class_materials/cbarcroft_gem
Submodule cbarcroft_gem added at e1d8be
Empty file.
1 change: 1 addition & 0 deletions week6/class_materials/gem/lib/test_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello"
12 changes: 12 additions & 0 deletions week6/class_materials/gem/test_gem.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Gem::Specification.new do |s|
s.name = 'test_gem'
s.version = '0.0.0'
s.date = '2012-11-13'
s.summary = 'Making a Test Gem'
s.description = "A gem to explain how to make gems"
s.authors = ["Renee D, Chris"]
s.email = "[email protected]"
s.homepage = ''
s.files = ['lib/test_gem.rb']
s.executables << "test_gem"
end
Loading