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

tic-tac-toe.rb #168

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions week6/class_materials/test_gem/test_gem.gemspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Gem::Specification.new do |s|
s.name = 'reneedv_hello_gem'
s.name = 'BrianTestGem'
s.version = '0.0.1'
s.date = '2012-11-13'
s.summary = "Making a Test Gem"
s.description = "A gem to explain how to make gems"
s.authors = ["Renée De Voursney"]
s.email = '[email protected]'
s.authors = ["Brian Torretta"]
s.email = '[email protected]'
s.homepage = 'http://rubygems.org/gems/test_gem'
s.files = ["lib/test_gem.rb"]
s.executables << 'test_gem'
end
end
18 changes: 0 additions & 18 deletions week7/exercises/features/puppy.feature

This file was deleted.

13 changes: 13 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8
class Pirate
def initialize(value)
@value = value
end

def translate(arg1)
if arg1 = ("Hello Friend")
then puts "Ahoy Matey"
puts "Shiber Me Timbers You Scurvey Dogs!!"
end
end
end
38 changes: 38 additions & 0 deletions week7/homework/features/step_definitions/pirate_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Given /^I say (\hello friend\i)$/ do |arg1|

# @pirate = Pirate.new(arg1)

#end


#When /^I hit (\w+)$/ do |arg1|

# @result = @pirate.send(arg1)

#end


#Then /^Let go and haul it prints out (\Ahoy Matey\)(\Shiber Me Timbers You Scurvey Dogs!!\)$/ do |arg1, arg2|

# @result.should == "#{arg1} #{arg2}"
#end
Gangway /^I have a PirateTranslator$/ do
@pirate = Pirate.new('Hello Friend') # express the regexp above with the code you wish you had
end

Blimey /^I say 'Hello Friend'$/ do
@pirate# express the regexp above with the code you wish you had
end

Blimey /^I hit translate$/ do
@pirate.translate("Hello Friend") # express the regexp above with the code you wish you had
end

Letgoandhaul /^it prints out 'Ahoy Matey'$/ do
pending # express the regexp above with the code you wish you had
end

Letgoandhaul /^it also prints 'Shiber Me Timbers You Scurvey Dogs!!'$/ do
pending # express the regexp above with the code you wish you had
end

90 changes: 90 additions & 0 deletions week7/homework/features/step_definitions/tic-tac-toe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# encoding: utf-8
class TicTacToe

SYMBOLS = [:X, :O]


attr_accessor :player, :X, :O

def initialize(player = :player)
@new_game = true
@player = player
#owe the new game trick to kris-luminar
if player == "Renee" then current_player(Renee) end

end

def player(*player)

#@player = player
i = puts "what is your name?"
player = gets.chomp
end



def welcome_player

"Welcome #{@player}"
end

def current_player(*player)
# if @new_game == true
players = [player, "Computer"]
first = players.sample
if first = player then second = "Computer" else second = player
end
# end

end

def player_symbol
:X
end

def computer_symbol
:O
end

#def indicate_palyer_turn
#end

#def get_player_move
#end

#def open_spots
#end

#def computer_move
#end

#def current_state
#end

# def spots_open?
#end

# def spots_open?
#end

#def player_won?
#end

#def computer_won?
#end

#def draw?
#end


@board = {

A1: " ", A2: " ", A3: " ",

B1: " ", B2: " ", B3: " ",

C1: " ", C2: " ", C3: " "

}

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

Questions:
1. What is method_missing and how can it be used?
If a method isn't found is the current class or any superclass, Ruby invokes method_missing and typically raises a nomethoderror or name error. We can overwrite the default behaviour with it's own method and error handling.
2. What is and Eigenclass and what is it used for? Where Do Singleton methods live?
Eigenclass, or singleton class p.369, is the class that is specific to a particular object and it is anonymous class. Singleton methods in live in the class of Object.
3. When would you use DuckTypeing? How would you use it to improve your code?
DuckTyping is always used by Ruby and it always for shorter, more concise coding.
4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval?
A class method is a method that works on a class and an instance method is one that only works on an instance of that class. Instance eval and class eval let you set self to be an arbitrary object, evaluate the code in a block and then reset self. Class eval's environment acts as if you were in the body of a class definition so methods will define instance methods. instance eval acts as if you were working inside a singleton class of self and any methods you define will become class methods.
5. What is the difference between a singleton class and a singleton method?
They are either method or classes that are specific to a particular object.