diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ff51aeb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+
+week2/homework/simon_says.rb
diff --git a/midterm/untitled.rb b/midterm/untitled.rb
new file mode 100644
index 0000000..e69de29
diff --git a/untitled.tmproj b/untitled.tmproj
new file mode 100644
index 0000000..1d1e532
--- /dev/null
+++ b/untitled.tmproj
@@ -0,0 +1,59 @@
+
+
+
+
+ documents
+
+
+ filename
+ week2/exercises/book_spec.rb
+ lastUsed
+ 2013-10-23T03:01:38Z
+
+
+ filename
+ week3/exercises/monster.rb
+
+
+ filename
+ week3/exercises/monsters.rb
+ lastUsed
+ 2013-10-23T03:28:51Z
+ selected
+
+
+
+ filename
+ week3/exercises/named_thing.rb
+
+
+ filename
+ week3/exercises/vampire.rb
+
+
+ filename
+ week2/exercises/book.rb
+ lastUsed
+ 2013-10-23T03:01:40Z
+
+
+ filename
+ week2/exercises/mad_libs.rb
+
+
+ filename
+ week2/homework/simon_says.rb
+ lastUsed
+ 2013-10-23T01:32:06Z
+
+
+ fileHierarchyDrawerWidth
+ 200
+ metaData
+
+ showFileHierarchyDrawer
+
+ windowFrame
+ {{210, 54}, {1070, 719}}
+
+
diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt
index bd581a6..f9347f5 100644
--- a/week1/homework/questions.txt
+++ b/week1/homework/questions.txt
@@ -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?
diff --git a/week1/homework/string-program.rb b/week1/homework/string-program.rb
new file mode 100644
index 0000000..8f07b20
--- /dev/null
+++ b/week1/homework/string-program.rb
@@ -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
diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb
index ea79e4c..0be5d3a 100644
--- a/week1/homework/strings_and_rspec_spec.rb
+++ b/week1/homework/strings_and_rspec_spec.rb
@@ -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
diff --git a/week2/.DS_Store b/week2/.DS_Store
index 6f2aa37..498d1c0 100644
Binary files a/week2/.DS_Store and b/week2/.DS_Store differ
diff --git a/week2/exercises/book.rb b/week2/exercises/book.rb
index a6b943d..49cca40 100644
--- a/week2/exercises/book.rb
+++ b/week2/exercises/book.rb
@@ -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
@@ -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
\ No newline at end of file
+end
+>>>>>>> fde8a74b427aa79cd14a4014401682c12225e82b
diff --git a/week2/exercises/book_spec.rb b/week2/exercises/book_spec.rb
index c3b1292..c8415f2 100644
--- a/week2/exercises/book_spec.rb
+++ b/week2/exercises/book_spec.rb
@@ -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
@@ -46,4 +75,5 @@
end
-end
\ No newline at end of file
+end
+>>>>>>> fde8a74b427aa79cd14a4014401682c12225e82b
diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt
index 939e42d..ea8c33f 100644
--- a/week2/homework/questions.txt
+++ b/week2/homework/questions.txt
@@ -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.
diff --git a/week2/homework/simon_says_spec.rb b/week2/homework/simon_says_spec.rb
index 7f329e5..c641f28 100644
--- a/week2/homework/simon_says_spec.rb
+++ b/week2/homework/simon_says_spec.rb
@@ -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
diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb
new file mode 100644
index 0000000..1eff83f
--- /dev/null
+++ b/week3/homework/calculator.rb
@@ -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
\ No newline at end of file
diff --git a/week3/homework/calculator_spec.rb b/week3/homework/calculator_spec.rb
index 5a418ed..a2144ee 100644
--- a/week3/homework/calculator_spec.rb
+++ b/week3/homework/calculator_spec.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/calculator"
+require "./calculator.rb"
describe Calculator do
@@ -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
diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt
index dfb158d..c83d703 100644
--- a/week3/homework/questions.txt
+++ b/week3/homework/questions.txt
@@ -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.
\ No newline at end of file
diff --git a/week4/Rakefile.rb b/week4/Rakefile.rb
new file mode 100644
index 0000000..63c0a92
--- /dev/null
+++ b/week4/Rakefile.rb
@@ -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
\ No newline at end of file
diff --git a/week4/class_materials/class_power.rb b/week4/class_materials/class_power.rb
new file mode 100644
index 0000000..278fd3f
--- /dev/null
+++ b/week4/class_materials/class_power.rb
@@ -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
\ No newline at end of file
diff --git a/week4/class_materials/untitled.rb b/week4/class_materials/untitled.rb
new file mode 100644
index 0000000..3f2ff2d
--- /dev/null
+++ b/week4/class_materials/untitled.rb
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/week4/code_timer.rb b/week4/code_timer.rb
new file mode 100644
index 0000000..0285d19
--- /dev/null
+++ b/week4/code_timer.rb
@@ -0,0 +1,9 @@
+class CodeTimer
+ def time_code
+ start_time = Time.now
+ yield
+ Time.now - start_time
+
+ end
+
+end
diff --git a/week4/filemaker.rb b/week4/filemaker.rb
new file mode 100644
index 0000000..4ca60a7
--- /dev/null
+++ b/week4/filemaker.rb
@@ -0,0 +1,2 @@
+File.open("output.txt", "w") { |file| file.puts "Hello"
+file.puts "1 + 2 = #{1+2}" }
diff --git a/week4/homework/my_output.txt b/week4/homework/my_output.txt
new file mode 100644
index 0000000..e69de29
diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt
index bc1ab7c..00093fd 100644
--- a/week4/homework/questions.txt
+++ b/week4/homework/questions.txt
@@ -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.
diff --git a/week4/homework/work.rb b/week4/homework/work.rb
new file mode 100644
index 0000000..d21fada
--- /dev/null
+++ b/week4/homework/work.rb
@@ -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
\ No newline at end of file
diff --git a/week4/homework/worker_spec.rb b/week4/homework/worker_spec.rb
new file mode 100644
index 0000000..a8bcfc1
--- /dev/null
+++ b/week4/homework/worker_spec.rb
@@ -0,0 +1,36 @@
+require './work.rb'
+
+describe Worker do
+
+ it "executes a block and returns a string" do
+ result = Worker.work do
+ "hello"
+ end
+ result.should == "hello"
+ end
+
+ it "executes a block and returns a number" do
+ result = Worker.work do
+ 3 + 4
+ end
+ result.should == 7
+ end
+
+ it "executes a block in the context of the calling method" do
+ n = 1
+ result = Worker.work do
+ n + 4
+ end
+ result.should == 5
+ end
+
+
+ it "executes a block 3 times and returns the result" do
+ n = 5
+ result = Worker.work(3) do
+ n += 1
+ end
+ result.should == 8
+ end
+
+end
diff --git a/week4/my_output.txt b/week4/my_output.txt
new file mode 100644
index 0000000..e69de29
diff --git a/week4/nameed_thing.rb b/week4/nameed_thing.rb
new file mode 100644
index 0000000..b8a3799
--- /dev/null
+++ b/week4/nameed_thing.rb
@@ -0,0 +1,10 @@
+module NameThing
+
+ def initialize name
+ @name = name
+ end
+
+ def shout
+ @name.upcase
+ end
+end
diff --git a/week4/output.txt b/week4/output.txt
new file mode 100644
index 0000000..273b43f
--- /dev/null
+++ b/week4/output.txt
@@ -0,0 +1,2 @@
+Hello
+1 + 2 = 3
diff --git a/week4/person.rb b/week4/person.rb
new file mode 100644
index 0000000..5995269
--- /dev/null
+++ b/week4/person.rb
@@ -0,0 +1,10 @@
+require './named_thing'
+
+class Person
+ include NamedThing
+
+ def shout_name
+ "My NAME IS #{@name.upcase}"
+ end
+
+end
diff --git a/week4/timer_spec.rb b/week4/timer_spec.rb
new file mode 100644
index 0000000..ab33a8c
--- /dev/null
+++ b/week4/timer_spec.rb
@@ -0,0 +1,24 @@
+require './code_timer.rb'
+
+describe CodeTimer do
+
+ it " should run out code " do
+ flag = false
+
+ CodeTimer.time_code do
+ flag = true
+ end
+ flag.should eq true
+ end
+
+ it "should timer our code" do
+ CodeTimer.time_code do
+ sleep(3)
+ puts "hi"
+ end
+
+ run_time.should be_within(0.1).of(3.0)
+
+
+ end
+end
diff --git a/week4/untitled.rb b/week4/untitled.rb
new file mode 100644
index 0000000..f55eb78
--- /dev/null
+++ b/week4/untitled.rb
@@ -0,0 +1,5 @@
+class vampire
+ attr_accessor :name
+
+end
+
diff --git a/week4/vampire.rb b/week4/vampire.rb
new file mode 100644
index 0000000..8aab7e6
--- /dev/null
+++ b/week4/vampire.rb
@@ -0,0 +1,10 @@
+require './named_thing'
+
+class Vampire
+ include NamedThing
+
+
+
+
+end
+
diff --git a/week5/exercises/Rakefile.rb b/week5/exercises/Rakefile.rb
new file mode 100644
index 0000000..cc316bd
--- /dev/null
+++ b/week5/exercises/Rakefile.rb
@@ -0,0 +1,7 @@
+#task :default => [:hello_world]
+
+desc "spits out the contents of the file"
+task :filereader do
+ a = File.open("names.txt", "r")
+ a.readlines
+end
\ No newline at end of file
diff --git a/week5/exercises/names b/week5/exercises/names.txt
similarity index 100%
rename from week5/exercises/names
rename to week5/exercises/names.txt
diff --git a/week5/homework/do_your_mid_term b/week5/homework/do_your_mid_term.txt
similarity index 100%
rename from week5/homework/do_your_mid_term
rename to week5/homework/do_your_mid_term.txt
diff --git a/week7/homework/.idea/.name b/week7/homework/.idea/.name
new file mode 100644
index 0000000..158b7eb
--- /dev/null
+++ b/week7/homework/.idea/.name
@@ -0,0 +1 @@
+homework
\ No newline at end of file
diff --git a/week7/homework/.idea/encodings.xml b/week7/homework/.idea/encodings.xml
new file mode 100644
index 0000000..e206d70
--- /dev/null
+++ b/week7/homework/.idea/encodings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/week7/homework/.idea/homework.iml b/week7/homework/.idea/homework.iml
new file mode 100644
index 0000000..e91821c
--- /dev/null
+++ b/week7/homework/.idea/homework.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/week7/homework/.idea/misc.xml b/week7/homework/.idea/misc.xml
new file mode 100644
index 0000000..01ea7d8
--- /dev/null
+++ b/week7/homework/.idea/misc.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/week7/homework/.idea/modules.xml b/week7/homework/.idea/modules.xml
new file mode 100644
index 0000000..f766474
--- /dev/null
+++ b/week7/homework/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/week7/homework/.idea/scopes/scope_settings.xml b/week7/homework/.idea/scopes/scope_settings.xml
new file mode 100644
index 0000000..922003b
--- /dev/null
+++ b/week7/homework/.idea/scopes/scope_settings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/week7/homework/.idea/vcs.xml b/week7/homework/.idea/vcs.xml
new file mode 100644
index 0000000..def6a6a
--- /dev/null
+++ b/week7/homework/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/week7/homework/.idea/workspace.xml b/week7/homework/.idea/workspace.xml
new file mode 100644
index 0000000..987d06c
--- /dev/null
+++ b/week7/homework/.idea/workspace.xml
@@ -0,0 +1,588 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/week7/homework/Gemfile b/week7/homework/Gemfile
new file mode 100644
index 0000000..5dc0645
--- /dev/null
+++ b/week7/homework/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem Cucumber
diff --git a/week7/homework/TicTacToe_game.rb b/week7/homework/TicTacToe_game.rb
new file mode 100644
index 0000000..3cb86c7
--- /dev/null
+++ b/week7/homework/TicTacToe_game.rb
@@ -0,0 +1,123 @@
+class TicTacToe
+ SYMBOLS = [:X,:O]
+ attr_accessor :player
+ attr_accessor :current_player
+ attr_accessor :player_symbol
+ attr_accessor :computer_symbol
+ attr_accessor :board_locations
+ attr_reader :winner
+
+ def initialize (name = " ",symbol = :X )
+ @winning_patterns = [
+
+ [:A1,:A2,:A3],
+ [:B1,:B2,:B3],
+ [:A1,:C2,:C3],
+ [:A1,:B1,:C1],
+ [:A2,:B2,:C2],
+ [:A3,:B3,:C3],
+ [:A1,:B2,:C3],
+ [:A3,:B2,:C1]
+
+ ]
+
+ @board_locations = {:A1 =>" ", :A2 =>" ", :A3 =>" ",
+ :B1 =>" ", :B2 =>" ", :B3 =>" ",
+ :C1 =>" ", :C2 =>" ", :C3 =>" "}
+ @location = " "
+ @move_counter = 0
+ @player_symbol = symbol
+ @player_symbol == :X ? @computer_symbol =:O : @computer_symbol =:X
+ end
+
+ def welcome_player
+ @welcome_player = "Welcome #{@player}"
+ end
+
+ def indicate_player_turn
+ puts "#{@player}'s Move:"
+ end
+
+ def current_player
+ case @move_counter
+ when @move_counter == 0
+ @player_on_deck = rand() > 0.5 ? "Computer" : @player
+ else
+ @player_on_deck = @player
+ end
+
+ @player_on_deck == @player ? symbol = @player_symbol : symbol = @computer_symbol
+
+ @move_counter += 1
+ @player_on_deck
+ end
+
+ def get_move
+ move = @player ? get_player_move : get_computer_move
+ end
+
+ def get_player_move
+ @location = gets.chomp.to_sym
+ end
+
+ def spots_open?
+ @board_locations.has_value?(' ')
+ end
+
+ def open_spots
+ @board_locations.select {|key,val| val == " "}.keys
+ end
+
+ def computer_move
+ @location = @board_locations.select {|key,val| val == " "}.keys.sample
+ @board_locations[@location] = computer_symbol
+ @location
+ end
+
+ def player_move
+ available = @board_locations[get_player_move.to_sym]
+ available == " " ? a= get_player_move.to_sym : a = get_player_move.to_sym
+ @board_locations[a] = @player_symbol.to_s
+ a
+ end
+
+ def current_state
+ @board_locations.to_s
+ end
+
+ def player_won?
+ @winner == " " ? state = FALSE : state = TRUE
+ state
+ end
+
+ def over?
+ player_won? == TRUE ? state = TRUE : state = FALSE
+ state
+
+ end
+
+ def draw?
+ spots_open? == TRUE ? state = FALSE : state = TRUE
+ state
+ end
+
+ def determine_winner
+ c = @board_locations.select {|key,val| val == @player_symbol.to_s}.keys
+ d = @board_locations.select {|key,val| val == @computer_symbol.to_s}.keys
+
+ case
+ when @winning_patterns.include?(c) == TRUE
+ @winner = @player
+ when @winning_patterns.include?(d) == TRUE
+ @winner = "Computer"
+ when @winning_patterns.include?(c) || @winning_patterns.include?(d) == FALSE
+ current_player
+ end
+ @winner
+ player_won?
+
+ end
+
+end
+
+
diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb
index a3287c1..de7473f 100644
--- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb
+++ b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb
@@ -1,64 +1,69 @@
require 'rspec/mocks/standalone'
require 'rspec/expectations'
+require '/Users/adam/Documents/Git_Repos/RubyFall2013-1/week7/homework/TicTacToe_game.rb'
+
+# Scenario: Begin Game
Given /^I start a new Tic\-Tac\-Toe game$/ do
@game = TicTacToe.new
end
When /^I enter my name (\w+)$/ do |name|
- @game.player = name
+ @game.player = name #
end
Then /^the computer welcomes me to the game with "(.*?)"$/ do |arg1|
- @game.welcome_player.should eq arg1
+ @game.welcome_player.should eq arg1 #
end
Then /^randomly chooses who goes first$/ do
- [@game.player, "Computer"].should include @game.current_player
+ [@game.player, "Computer"].should include @game.current_player #
end
Then /^who is X and who is O$/ do
- TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol
+ TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol #
end
-Given /^I have a started Tic\-Tac\-Toe game$/ do
+# Scenario: My Turn
+
+Given /^I have a started Tic\-Tac\-Toe game$/ do #
@game = TicTacToe.new(:player)
- @game.player = "Renee"
+ @game.player = "Renee" #
end
-Given /^it is my turn$/ do
+Given /^it is my turn$/ do #
@game.current_player.should eq "Renee"
end
-Given /^the computer knows my name is Renee$/ do
+Given /^the computer knows my name is Renee$/ do #
@game.player.should eq "Renee"
end
Then /^the computer prints "(.*?)"$/ do |arg1|
- @game.should_receive(:puts).with(arg1)
- @game.indicate_palyer_turn
+ @game.should_receive(:puts).with(arg1) #
+ @game.indicate_player_turn
end
Then /^waits for my input of "(.*?)"$/ do |arg1|
- @game.should_receive(:gets).and_return(arg1)
+ @game.should_receive(:gets).and_return(arg1) #
@game.get_player_move
end
-Given /^it is the computer's turn$/ do
+Given /^it is the computers turn$/ do #
@game = TicTacToe.new(:computer, :O)
@game.current_player.should eq "Computer"
end
-Then /^the computer randomly chooses an open position for its move$/ do
- open_spots = @game.open_spots
+Then /^the computer randomly chooses an open position for its move$/ do #
+ open_spots = @game.open_spots #
@com_move = @game.computer_move
open_spots.should include(@com_move)
end
-Given /^the computer is playing X$/ do
+Given /^the computer is playing X$/ do #
@game.computer_symbol.should eq :X
end
-Then /^the board should have an X on it$/ do
+Then /^the board should have an X on it$/ do #
@game.current_state.should include 'X'
end
@@ -68,22 +73,22 @@
end
When /^I enter a position "(.*?)" on the board$/ do |arg1|
- @old_pos = @game.board[arg1.to_sym]
+ @old_pos = @game.board_locations[arg1.to_sym]
@game.should_receive(:get_player_move).and_return(arg1)
- @game.player_move.should eq arg1.to_sym
+ @game.player_move.should eq arg1.to_sym #
end
When /^"(.*?)" is not taken$/ do |arg1|
@old_pos.should eq " "
end
-Then /^it is now the computer's turn$/ do
+Then /^it is now the computers turn$/ do
@game.current_player.should eq "Computer"
end
-When /^there are three X's in a row$/ do
+When /^there are three Xs in a row$/ do
@game = TicTacToe.new(:computer, :X)
- @game.board[:C1] = @game.board[:B2] = @game.board[:A3] = :X
+ @game.board_locations[:C1] = @game.board_locations[:B2] = @game.board_locations[:A3] = :X
end
Then /^I am declared the winner$/ do
@@ -96,7 +101,7 @@
end
Given /^there are not three symbols in a row$/ do
- @game.board = {
+ @game.board_locations = {
:A1 => :X, :A2 => :O, :A3 => :X,
:B1 => :X, :B2 => :O, :B3 => :X,
:C1 => :O, :C2 => :X, :C3 => :O
@@ -113,12 +118,29 @@
end
When /^"(.*?)" is taken$/ do |arg1|
- @game.board[arg1.to_sym] = :O
+ @game.board_locations[arg1.to_sym] = :O
@taken_spot = arg1.to_sym
end
Then /^computer should ask me for another position "(.*?)"$/ do |arg1|
- @game.board[arg1.to_sym] = ' '
+ @game.board_locations[arg1.to_sym] = ' '
@game.should_receive(:get_player_move).twice.and_return(@taken_spot, arg1)
@game.player_move.should eq arg1.to_sym
end
+
+
+Then /^it is now the computer's turn$/ do
+ @game.current_player= "Computer"
+ @game.computer_move
+end
+
+When /^there are three X's in a row$/ do
+ @game = TicTacToe.new(:player, :X)
+ @game.board_locations[:C1] = @game.board_locations[:C2] = @game.board_locations[:C3] = :X
+end
+
+And /^it is the computer's turn$/ do
+ @game.current_player= "Computer"
+ @game.computer_symbol = :X
+ @game.computer_move
+end
\ No newline at end of file
diff --git a/week7/homework/features/support/env.rb b/week7/homework/features/support/env.rb
new file mode 100644
index 0000000..69f0efe
--- /dev/null
+++ b/week7/homework/features/support/env.rb
@@ -0,0 +1,2 @@
+require 'rspec/expectations'
+World(RSpec::Matchers)
diff --git a/week7/homework/features/tic-tac-toe.feature b/week7/homework/features/tic-tac-toe.feature
index 6f3134d..1411165 100644
--- a/week7/homework/features/tic-tac-toe.feature
+++ b/week7/homework/features/tic-tac-toe.feature
@@ -3,7 +3,7 @@ Feature: Tic-Tac-Toe Game
In order to up my skills
I would like to play agaist the computer
-Scenario: Begin Game
+Scenario: Begin Game
Given I start a new Tic-Tac-Toe game
When I enter my name Renee
Then the computer welcomes me to the game with "Welcome Renee"
diff --git a/week7/homework/pirate_translator.rb b/week7/homework/pirate_translator.rb
new file mode 100644
index 0000000..e891d17
--- /dev/null
+++ b/week7/homework/pirate_translator.rb
@@ -0,0 +1,3 @@
+require './features/step_definitions/pirate_steps.rb'
+
+
diff --git a/week7/homework/play_game.rb b/week7/homework/play_game.rb
index 0535830..7437824 100644
--- a/week7/homework/play_game.rb
+++ b/week7/homework/play_game.rb
@@ -1,4 +1,6 @@
-require './features/step_definitions/tic-tac-toe.rb'
+require './features/step_definitions/tic-tac-toe-steps.rb'
+require './TicTacToe_game.rb'
+
@game = TicTacToe.new
puts "What is your name?"
diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt
index d55387d..60cb009 100644
--- a/week7/homework/questions.txt
+++ b/week7/homework/questions.txt
@@ -3,7 +3,22 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming
Questions:
1. What is method_missing and how can it be used?
-2. What is and Eigenclass and what is it used for? Where Do Singleton methods live?
-3. When would you use DuckTypeing? How would you use it to improve your code?
-4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval?
+When an object it cannot handel the method_missing method can be used to implement proxies, delegators, and forwarders (of which i have no idea what they are)
+
+2. What is and Eigenclass and what is it used for?
+-An Eigenclass is an anonymous that is created when you create a singleton method. It defines the singleton methods we create.
+Where Do Singleton methods live?
+-In the singleton class or Eigenclass
+
+3. When would you use DuckTypeing?
+-When the inputs my code will work on can be in a variety of types and the operations that i the code will perform is independant of the format of the input.
+How would you use it to improve your code?
+-I would use the Ducktyping Style of coding to make my code more flexible. It can focus more on the contents of the inputs instead of the format of the input.
+
+4. What is the difference between a class method and an instance method?
+-A class method can modify can work on the class level. It can manage all of the items for various instances of the class. An instance method only works at the instance level. It cannot operate on another instance of the same class.
+What is the difference between instance_eval and class_eval?
+-Class_eval defined instance methods and instance_eval defines class methods.
+
5. What is the difference between a singleton class and a singleton method?
+-A singleton class is a anonymous class that defines the singleton methods we create. Singleton methods are created by to be methods that are specific to an object.
diff --git a/week8/class_materials/couch.rb b/week8/class_materials/couch.rb
index a919c51..b709d13 100644
--- a/week8/class_materials/couch.rb
+++ b/week8/class_materials/couch.rb
@@ -11,6 +11,22 @@ def initialize(pillows, cushions, dogs)
end
end
+
+ [:pillows, :cushions, :dogs].each do |var|
+ define_method("how_many_#{var}") do
+ instance_variable_get("@#{var}").size
+ end
+
+ end
+
+
+# non dry way
+ # def how_many_pillows
+ # @pillows.size
+
+ # end
+
+
# def to_str
# "I am a Couch"
# end
diff --git a/week8/exercises/couch.rb b/week8/exercises/couch.rb
index b8c8d4b..6a4f6e3 100644
--- a/week8/exercises/couch.rb
+++ b/week8/exercises/couch.rb
@@ -9,4 +9,16 @@ def initialize(pillows, cushions)
instance_variable_get("@#{s}").count
end
end
+
+ [:pillows, :cushions,].each do |x|
+ define_method("what_color_are_the_#{x}") do
+ instance_variable_get("@#{x}").each do |color| puts color end
+ end
+ # def method_missing method_name, *args, &block
+ # puts "you called #{method_name}"
+
+ # end
+
+
+ end
end
\ No newline at end of file