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

What I have so far of TicTacToe #119

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a90fb6a
First commit with change to roster, rspec_spec.rb (in class exercise)…
kodywilson Jan 27, 2014
7c6391e
Altered .gitignore to add .project which was created by Aptana Studio…
kodywilson Jan 27, 2014
9cb6cbf
Finished answering questions and doing the homework for week 1.
kodywilson Jan 28, 2014
30610be
Completed all week 2 homework.
kodywilson Jan 29, 2014
b71d960
Removed extra repeat code block in simon_says.rb
kodywilson Jan 29, 2014
96b97a8
Cleaned up merge conflicts from git pull upstream master and reverted…
kodywilson Jan 29, 2014
b8fffac
Adding some changes to the week3 in class exercises as I follow along.
kodywilson Jan 30, 2014
132f167
Committing changes made on work computer to my fork. These are the in…
kodywilson Jan 31, 2014
3b477a3
Week 3 homework (Calculator). Still need to do questions.
kodywilson Feb 7, 2014
9951070
Merge remote branch 'upstream/master'
kodywilson Feb 11, 2014
578c90b
One correction to the week 3 homework and I answered the questions fo…
kodywilson Feb 13, 2014
b4d9c40
Week 4 homework.
kodywilson Feb 18, 2014
49f02af
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kodywilson Feb 18, 2014
8d7e5f3
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kodywilson Feb 21, 2014
80b54f7
Week 5 in-class exercises.
kodywilson Feb 27, 2014
ec81fa4
Built my test gem, jim_gem_gym
kodywilson Feb 27, 2014
27b506a
Added executable to my learning gem, jim_gem_gym
kodywilson Feb 27, 2014
4fb7c0b
Added ability to take parameters to jim_gem_gym
kodywilson Feb 27, 2014
9cbd4ea
Added Rakefile and rspec for tests.
kodywilson Feb 27, 2014
bc51d1f
Worked through cool_game in class exercise.
kodywilson Feb 28, 2014
e72a183
Still working through the in class exercises from 02202014
kodywilson Feb 28, 2014
752de20
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kodywilson Feb 28, 2014
c7d1608
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kodywilson Feb 28, 2014
40973d8
Merge branch 'master' of https://github.com/kodywilson/RubyWinter2014
kodywilson Mar 12, 2014
0380274
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kodywilson Mar 12, 2014
e0ace39
Progress so far on TicTacToe: first scenario is passing and I have ch…
kodywilson Mar 13, 2014
2be7225
Both first and second scenario's passing now.
kodywilson Mar 13, 2014
658d388
What I have so far for tictactoe.
kodywilson Mar 13, 2014
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.project
1 change: 1 addition & 0 deletions week1/exercises/roster.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
18,
19,
20, Zack Walkingstick, [email protected], zackwalkingstick, no twitter, @zack
21, Kody Wilson, [email protected], kodywilson, @kodykwilson, Kody Wilson
4 changes: 2 additions & 2 deletions week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

# When this example fails,
# it will show "expected" as 2, and "actual" as 1
1.should eq 2
1.should eq 1

end

Expand Down Expand Up @@ -80,7 +80,7 @@
((((1+2)-5)*6)/2).should eq -6
end
it "should count the characters in your name" do
"Tom".should have(3).characters
"Kody".should have(4).characters
end

it "should check basic math" do
Expand Down
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 you manipulate is an object, and the results of those manipulations are themselves objects.

2. What is a variable?
A reference to an object.

3. What is the difference between an object and a class?
A class is a way to define methods for objects and is an object itself.

4. What is a String?
Strings are objects holding sequences of characters.

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

6. What are two ways of defining a String literal? Bonus: What is the difference between them?
single quotes = fewer escape sequences, usually used when you don't need something in the quotes to change (no interpolation).
double quotes = lots of escape sequences and interpolation, ie. "#{some_var} is awesome!" to add some_var to string.
12 changes: 7 additions & 5 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
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 characters" do
@my_string.should have(66).characters
end
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
result.should have(2).items
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"))'
encode = @my_string.encoding
encode.should eq (Encoding.find("UTF-8"))
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
Arrays are indexed by integers while hashes are indexed with objects of any type.
In a hash, each value has two objects, the index (key) and associated entry.

2. When would you use an Array over a Hash and vice versa?
You would use an array if you do not need non-integer indexing as arrays are more efficient than hashes.
Maybe a better way to put it is that sometimes being able to reference values by their keys
is super handy so you would choose a hash in that case.

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.
They provide namespace and prevent name clashes and support the mixin facility.
Enumerable is a standard mixin, implementing a bunch of methods in terms of the host class’s
each method.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
A Ruby class has only one direct parent, so Ruby is a single-inheritance language.
To circumvent this problem, Ruby classes can include the functionality of any number of mixins.

5. What is the difference between a Module and a Class?
Modules support the mixin facility and prevent name clashes.
17 changes: 17 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SimonSays
def echo(greet)
greet
end
def shout(scream)
scream.upcase
end
def repeat(greet, quant=2)
("#{greet} " * quant).chop
end
def start_of_word (word, place)
word[0...place]
end
def first_word(phrase)
phrase.split.first
end
end
2 changes: 2 additions & 0 deletions week3/exercises/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format nested
26 changes: 23 additions & 3 deletions week3/exercises/book.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
class Book
$global_hello = "hi there"

def pages
module Library
class Book
HELLO = "hello I shouldn't change..."

end
attr_accessor :pages, :title

@@library_count = 0

def self.library_count
@@library_count
end

def initialize pages = 1, title="N/A"
@pages = pages
@title = title
@@library_count += 1
end

def happy
$global_hello = "hello"
"There are #{@pages} happy pages in this book"
end

end
end
32 changes: 28 additions & 4 deletions week3/exercises/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@

describe Book do

it "should have a pages" do
book = Book.new
book.should respond_to "pages"
before :each do
@book = Book.new 542, "Programming Ruby"
end


context "::library_count" do
it "should tell us how many books are in our library" do
3.times{ Book.new 3 }
Book.library_count.should eq 4
end
end

context "#pages" do

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

it "should allow us to set the number of pages" do
@book.pages.should eq 542
end

end

context "#title" do
it "should let us read the title" do
@book.title.should eq "Programming Ruby"
end
end

end
7 changes: 7 additions & 0 deletions week3/exercises/human.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative 'named_thing'
require_relative 'other_thing'

class Human
include NamedThing
include OtherThing
end
5 changes: 5 additions & 0 deletions week3/exercises/monster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ def initialize(noc, legs, name="Monster", vul = [], dangers = [])
@dangers = dangers
@legs = legs
end

def attack! human
puts "hi from Monster"
end

end
5 changes: 5 additions & 0 deletions week3/exercises/other_thing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OtherThing
def say_name
"hello"
end
end
8 changes: 8 additions & 0 deletions week3/exercises/vampire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ class Vampire < Monster
def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites])
super(noc,legs,name,vul,dangers)
end

def bite! human

end

def attack! human
puts "hi from Vampire"
end
end
9 changes: 9 additions & 0 deletions week3/exercises/zombie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require_relative 'named_thing'

class Zombie
include NamedThing

def say_name
"uuurrrrggggghhhhh #{@name}"
end
end
2 changes: 2 additions & 0 deletions week3/homework/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format nested
14 changes: 14 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Calculator
def sum numbers
numbers.inject 0, :+
end
def multiply *numbers
numbers.flatten.inject 1, :*
end
def pow x, y
x**y
end
def fac x
multiply (1..x).to_a
end
end
10 changes: 10 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ Please Read:
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants

1. What is a symbol?
A symbol is an identifier corresponding to a string of characters, often a name.
They cannot be changed, only overwritten.

2. What is the difference between a symbol and a string?
Symbols are immutable (cannot be changed, same object id) while strings are not.

3. What is a block and how do I call a block?
A block is a chunk of code enclosed between either braces or the keywords do
and end. Blocks can take parameters and are called by a method (like they are
another parameter passed to a method).

4. How do I pass a block to a method? What is the method signature?
You just put the code after the invocation of the method. I think a method signature
is the name of the method and the paramaters that are required.

5. Where would you use regular expressions?
Any time you need to match a pattern in a string. Like say you were trying to
see if the word "kitten" is in a line of text or if a line starts with "Once", etc.
27 changes: 27 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
It uses the base class IO, with the sub class, File.

2. How would you output "Hello World!" to a file called my_output.txt?
Here is one way, using irb:
xabv@V00970630 ~/code/ruby/
$ irb
irb(main):001:0> File.open("my_output.txt", "w") do |file|
irb(main):002:1* file.puts "Hello World!"
irb(main):003:1> end
=> nil
irb(main):004:0> exit

xabv@V00970630 ~/code/ruby/
$ ls
my_output.txt

xabv@V00970630 ~/code/ruby/
$ cat my_output.txt
Hello World!

3. What is the Directory class and what is it used for?
Objects of class Dir (directory) are directory streams representing
directories in the underlying filesystem. They provide many methods
to manipulate, delete, list, etc. directories and their contents.

4. What is an IO object?
An IO object is a bidirectional channel between a Ruby program and some
external resource.

5. What is rake and what is it used for? What is a rake task?
Rake is a gem that provides capabilities similar to make (you can build
programs with it) using settings found in rakefiles.

A rake task is a section of code in a rakefile that performs a job.
It might do a unit test or build a tarball for example. I guess you
could think of it as one piece of an install for a ruby program.
7 changes: 7 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Worker
def self.work n = 1
x = nil
n.times { x = yield }
x
end
end
40 changes: 40 additions & 0 deletions week5/exercises/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# names and class Rakefile

desc "Read names from file and print them out"
task :print_names do
file_helper("names") do |line|
puts line
end
end

desc "Creates class directory"
task :make_directory do
Dir.mkdir "class" unless Dir.exists? "class"
end

desc "Create directories using names in class directory"
task :name_directories => [:make_directory] do
Dir.chdir("class")
file_helper("../names") do |line|
Dir.mkdir line unless Dir.exists? line
end
Dir.chdir("..")
end

desc "clean up the directories we created"
task :remove_all_dirs => [:name_directories] do
Dir.chdir("class")
file_helper("../names") do |line|
Dir.rmdir line if Dir.exists? line
end
Dir.chdir("..")
Dir.rmdir("class")
end

def file_helper file_name
File.open(file_name) do |f|
f.each do |line|
yield line.chomp
end
end
end
10 changes: 10 additions & 0 deletions week5/exercises/ex_rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
task :default => [:say_hello, :say_hi]
desc "Outputs hello world"
task :say_hello do
puts "hello world"
end

desc "Outputs Hi"
task :say_hi do
puts "Hi"
end
3 changes: 3 additions & 0 deletions week6/homework/jim_gem_gym/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('spec')
task :default => :spec
7 changes: 7 additions & 0 deletions week6/homework/jim_gem_gym/bin/jim_gem_gym
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

require 'jim_gem_gym'

paradigm = ARGV.first || "benign"

puts Reality.new(paradigm).worldview
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading