Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final #70

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ece178d
Update strings_and_rspec_spec.rb
ktrops Oct 9, 2014
143ea75
Update questions.txt
ktrops Oct 10, 2014
b1dd139
Merge pull request #1 from UWE-Ruby/master
ktrops Oct 10, 2014
25cb2cd
Update questions.txt
ktrops Oct 16, 2014
500e6f9
Homework for week 2; Katie
ktrops Oct 16, 2014
3f3604f
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2014
ktrops Oct 17, 2014
e08997b
homework for week 3
ktrops Oct 24, 2014
2b6079f
week2 hw
ktrops Oct 24, 2014
d99a26b
Merge branch 'master' of https://github.com/ktrops/RubyFall2014
ktrops Oct 24, 2014
b8624b4
Update questions.txt
ktrops Oct 24, 2014
fbdb37d
Update calculator.rb
ktrops Oct 24, 2014
2917825
To commit changes to calculator.rb
ktrops Oct 29, 2014
70b2fa1
to conclude merge
ktrops Oct 29, 2014
5705162
Merge remote-tracking branch 'upstream/master'
ktrops Oct 29, 2014
f305230
to add worker.rb
ktrops Oct 31, 2014
0aefec9
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2014
ktrops Oct 31, 2014
2e6769a
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2014
ktrops Nov 7, 2014
9e8331b
to add files
ktrops Nov 14, 2014
a4b20ed
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2014
ktrops Nov 14, 2014
063a7ef
to add homework for week7
ktrops Nov 20, 2014
1511bfd
Merge remote-tracking branch 'upstream/master'
ktrops Nov 26, 2014
1044632
Merge remote-tracking branch 'upstream/master'
ktrops Dec 5, 2014
754f6de
for final
ktrops Dec 11, 2014
78226cd
my code for the final
ktrops Dec 11, 2014
5ad3a2c
for final
ktrops Dec 11, 2014
62aea11
for final
ktrops Dec 11, 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
5 changes: 5 additions & 0 deletions midterm/instructions_and_questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ Instructions for Mid-Term submission and Git Review (10pts):

Questions (20pts):
- What are the three uses of the curly brackets {} in Ruby?

T
- What is a regular expression and what is a common use for them?
- What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby?
Floats are saved by the same object id, saves them as a singleton above 32 bits it doesn’t freeze it anymore
symbols are fixed strings, its a singleton, it is always the same symbol when you reference it.saves on memorygit
in contrast when you use strings a a differnt instance when referenced by the same characters
- Are these two statements equivalent? Why or Why Not?
1. x, y = "hello", "hello"
2. x = y = "hello"
Expand Down
10 changes: 5 additions & 5 deletions midterm/mid_term_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../spec_helper.rb'
require_relative '../spec_helper.rb'
require "#{File.dirname(__FILE__)}/turkey"

describe Turkey do
Expand All @@ -12,7 +12,7 @@
end

it "should be a kind of animal" do
@turkey.kind_of?(Animal).should be_true
@turkey.kind_of?(Animal).should be_truthy
end

it "should gobble speak" do
Expand All @@ -31,7 +31,7 @@
end

it "should be a kind of dinner" do
@t_dinner.kind_of?(Dinner).should be_true
@t_dinner.kind_of?(Dinner).should be_truthy
end

# Use inject here
Expand All @@ -40,7 +40,7 @@
end

it "should provide a menu" do
@t_dinner.respond_to?(:menu).should be_true
@t_dinner.respond_to?(:menu).should be_truthy
end

context "#menu" do
Expand All @@ -54,7 +54,7 @@
end

it "should have vegetables" do
@t_dinner.menu[:veggies].should eq [:ginger_carrots , :potatoes, :yams]
@t_dinner.menu[:veggies].should eq [:ginger_carrots, :potatoes, :yams]
end

# Dinners don't always have dessert, but ThanksgivingDinners always do!
Expand Down
16 changes: 16 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?

An object is a data structure that interacts with its own code, in other words, anything we manipulate in Ruby.

2. What is a variable?

A variable labels and holds data, like an integer or a string.

3. What is the difference between an object and a class?

An object is a class instance and a class contains class instances.
Classes contain objects that interact with methods and each other.

4. What is a String?

A string is a sequence of characters that are sometimes printable. In Ruby, there are many built-in methods
that can be used on strings.

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

String#split, String#scan, String#chomp.

6. What are two ways of defining a String literal? Bonus: What is the difference between them?

To define a String literal you can use single quotes (‘ ’), double quotes (“ “), %q, %Q, or here documents.
%q and %Q are the same as single quotes and double quotes.
Here documents are treated as a section of source code and they can be used to create multiline strings.
12 changes: 6 additions & 6 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
@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.length.should eq 66
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"))'
encodeing #do something with @my_string here
#use helpful hint here
encode_result = @my_string.encoding
encode_result.should eq Encoding.find("UTF-8")
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
A Hash has key-value pairs that can be any object and an Array uses only integers as an index.

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

An Array is used when you have an ordered list and it's ok to have an integer for the index. Also, it's easier to use an Array for iteration.
A Hash is used when you want to store information using a key that is not an integer.

3. What is a module? Enumerable is a built in Ruby module, what is it?
A module is a collection of constants and methods. Enumerable has methods used for searching and sorting collections (i.e. Hash and Array).

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
A class can only inherit from one parent class, but by using Mixin Modules you can simulate multiple inheritance.

5. What is the difference between a Module and a Class?
<<<<<<< HEAD
Modules you can use across multiple classes. Modules are about functions and constants and classes are about objects and instances.
=======
Modules you can use across multiple classes. Modules are about functions and constants and classes are about objects and instances.
>>>>>>> 500e6f9d77bbce46d757bf3757289e7e5b1b69ae
28 changes: 28 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class SimonSays
def echo answer
puts answer
end
def shout phrase
puts phrase.upcase
end
def repeat (text, num)
if num == nil
num = 1
num.times do
puts text
end
else
num.times do
puts text
end
end
end
def start_of_word(text, num)
index = num - 1
puts text[0..index]

end
def first_word(text)
puts text.split(' ').first
end
end
2 changes: 1 addition & 1 deletion week2/homework/simon_says_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Hint: require needs to be able to find this file to load it
require_relative "simon_says.rb"
require_relative 'simon_says.rb'
require_relative '../../spec_helper'

describe SimonSays do
Expand Down
41 changes: 41 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Calculator
<<<<<<< HEAD

def sum input
if input == []
=======
attr_accessor :collection, :num


def sum (collection)
if collection == []
>>>>>>> fbdb37d62bfd89ad8328fe90edf6957bc997e776
return 0
else
total = input.inject(:+)
end
total
end
def multiply *input
if input.class == String
return input.to_a.inject(:*)
else
return input.inject(:*)

end

def pow (collection, num)
b = 1
num.times{b *= collection}
end
def fac (num)
if num == 0
return 1
else
array = (1..num).to_a
return array.inject(:*)
end
end
end
end
end
11 changes: 11 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Please Read:
- Chapter 6 Standard Types
- Review Blocks
Expand All @@ -6,10 +7,20 @@ Please Read:

1. What is a symbol?

A symbol is a constant name that is guaranteed to be unique and contain the same value through out the entire program.

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

Symbols are immutable, where as strings are mutable. Symbols are often used as hash keys because they are immutable.

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

A block is code between do and end or between brackets. An iterator method can call a block. The format for a block is first you have a collection for the method to iterator over then you have the keyword “do” or a open curly bracket then the value to be passed in, then the code, and finally a closing curly bracket or and “end” keyword.

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

By using the keyword yield you can pass a block to a method. You can also pass parameters to a block and a method can receive values from a block using method. The method signature is the method name with the parameter list.

5. Where would you use regular expressions?

You can use a regular expression to test a string for a matching pattern, to extract a matching pattern from a string, and substitution.
15 changes: 15 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?

Ruby reads a line from a standard input or files specified when gets or file.gets is used.
There are also iterators you can use to read files. IO#each_byte iterates over 8-bit bytes from the IO object. IO#each_line calls the block with each line from the file. IO#foreach opens the file to read, calls the block on one line from the file then closes the file. IO#read gets an entire file into a string or into an array of lines.

2. How would you output "Hello World!" to a file called my_output.txt?

File.open(“my_output.txt”, “w”) do |file|
file.puts “Hello World!”
end

puts File.read(“my_output.txt”)

3. What is the Directory class and what is it used for?

the Directory class is a way to list files and directories in Ruby. You can make instances of the Dir class and you can iterate over an object of the Dir class.

4. What is an IO object?

An IO object is a way for a ruby program to write to or read from an external resource.

5. What is rake and what is it used for? What is a rake task?

Rake is an internal Domain Specific Language based in Ruby. Rake has libraries that make it easy to do tasks that are common during the build and deploy process. You can define a rake task to customize it or if you don’t define a rake task then it defaults to test.
19 changes: 19 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Worker
def self.work (*t)
if t == []
yield
else
n = t[0]
num = 0
while num < n
num += 1
total = yield
end
total



end

end
end
4 changes: 2 additions & 2 deletions week7/homework/features/pirate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Ahoy matey!: Pirate Speak
Heave to: The mighty speaking pirate
Gangway! I have a PirateTranslator
Blimey! I say 'Hello Friend'
Aye I hit translate
Aye I hit translate
Let go and haul it prints out 'Ahoy Matey'
Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!'
Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!'
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 say(arg)
@hi = "Ahoy Matey"
return @hi
end

def translate
return "#{@hi}\n Shiber Me Timbers You Scurvey Dogs!!"
end
end
22 changes: 22 additions & 0 deletions week7/homework/features/step_definitions/play_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require './features/step_definitions/tic-tac-toe.rb'

@game = TicTacToe.new
puts "What is your name?"
@game.player = gets.chomp
puts @game.welcome_player

until @game.over?
case @game.current_player
when "Computer"
@game.computer_move
when @game.player
@game.indicate_player_turn
@game.player_move
end
puts @game.current_state
@game.determine_winner
end

puts "You Won!" if @game.player_won?
puts "I Won!" if @game.computer_won?
puts "DRAW!" if @game.draw?
18 changes: 9 additions & 9 deletions week7/homework/features/step_definitions/tic-tac-toe-steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

Then /^the computer prints "(.*?)"$/ do |arg1|
@game.should_receive(:puts).with(arg1)
@game.indicate_palyer_turn
@game.indicate_player_turn
end

Then /^waits for my input of "(.*?)"$/ do |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
Expand Down Expand Up @@ -77,22 +77,22 @@
@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
@game = TicTacToe.new(:computer, :X)
When /^there are three Xs in a row$/ do
@game = TicTacToe.new(:player, :X) #computer
@game.board[:C1] = @game.board[:B2] = @game.board[:A3] = :X
end

Then /^I am declared the winner$/ do
@game.determine_winner
@game.player_won?.should be_true
@game.player_won?.should be_truthy
end

Then /^the game ends$/ do
@game.over?.should be_true
@game.over?.should be_truthy
end

Given /^there are not three symbols in a row$/ do
Expand All @@ -105,11 +105,11 @@
end

When /^there are no open spaces left on the board$/ do
@game.spots_open?.should be_false
@game.spots_open?.should be_falsey
end

Then /^the game is declared a draw$/ do
@game.draw?.should be_true
@game.draw?.should be_truthy
end

When /^"(.*?)" is taken$/ do |arg1|
Expand Down
Loading