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

Fina + final project #128

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Empty file added .gem/credentials
Empty file.
Empty file added .gem/lib/test_gem.rb
Empty file.
Binary file added .gem/test_gem-0.0.0.gem
Binary file not shown.
11 changes: 11 additions & 0 deletions .gem/test_gem.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Gem::Specification.new do |s|
s.name = 'test_gem_Thomas'
s.version = '0.0.0'
s.date = '2013-11-19'
s.summary = "Make a Test Gem"
s.description = "A gem to get a grade"
s.authors = ["Thomas Osborn"]
s.email = '[email protected]'
s.homepage = 'http://rubygems.org/gems/test_gem'
s.files = ["lib/test_gem.rb"]
end
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_store
Empty file added lib/test_gem.rb
Empty file.
2 changes: 2 additions & 0 deletions midterm/animal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Animal
end
2 changes: 2 additions & 0 deletions midterm/dinner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Dinner
end
4 changes: 2 additions & 2 deletions midterm/mid_term_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# Dinners don't always have dessert, but ThanksgivingDinners always do!
it "should have desserts" do
@t_dinner.menu[:desserts].should eq({:pies => [:pumkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]})
@t_dinner.menu[:desserts].should eq({:pies => [:pumpkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]})
end

end
Expand All @@ -69,6 +69,6 @@
end

it "should return what is on the dessert menu" do
@t_dinner.whats_for_dessert.should eq "Tonight we have 5 delicious desserts: Pumkin Pie, Chocolate Moose, and 3 molds: Cranberry and Mango and Cherry."
@t_dinner.whats_for_dessert.should eq "Tonight we have 5 delicious desserts: Pumpkin Pie, Chocolate Moose, and 3 molds: Cranberry and Mango and Cherry."
end
end
24 changes: 24 additions & 0 deletions midterm/thanksgiving_dinner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require './dinner.rb'

class ThanksgivingDinner < Dinner

def initialize(diet)
@diet = diet
end

def guests=(guests)
@guests = guests
end

def seating_chart_size
@guests.inject(0) {|n, i| n += i.length }
end

def menu
{ diet: @diet, proteins: ["Tofurkey", "Hummus"], veggies: [:ginger_carrots , :potatoes , :yams], desserts: ({:pies => [:pumpkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]}) }
end

def whats_for_dinner
@t_dinner.menu
end
end
17 changes: 17 additions & 0 deletions midterm/turkey.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require './animal.rb'

class Turkey < Animal

def initialize(weight)
end

def weight
weight = 10
end

def gobble_speak(turkey_words)
turkeys_words = "Gobble Gobble Gobble gobble Gobble. Gobble Gobb'le Gobble Gobble."
end

end

Empty file added test_gem.rb
Empty file.
Binary file added test_gem_Thomas-0.0.0.gem
Binary file not shown.
11 changes: 11 additions & 0 deletions test_gem_Thomas.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Gem::Specification.new do |s|
s.name = 'test_gem_Thomas'
s.version = '0.0.0'
s.date = '2013-11-19'
s.summary = "Make a Test Gem"
s.description = "A gem to get a grade"
s.authors = ["Thomas Osborn"]
s.email = '[email protected]'
s.homepage = 'http://rubygems.org/gems/test_gem'
s.files = ["lib/test_gem.rb"]
end
12 changes: 12 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?

An object is anything "we manipulate in Ruby." This would not, for example, include variables, because a variable is merely a reference to an object.

2. What is a variable?

A variable is a reference to an object.

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

A class is an object, but an object is not necessarily a class. Any class is an object of the class Class, and like any object it will inherit relevant class properties. However unlike a class a non-class object will not contain methods or reference a superclass.

4. What is a String?

Strings are sequences of characters. They are objects of class String.

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

chomp, split, count

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

You can define a string literal by wrapped text in either single quotes or double quotes. The difference between the two is that a double quoted string can support more escape sequences.
11 changes: 6 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,15 @@
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 split on the . charater" do
pending
result = #do something with @my_string here
it "should be able to count the characters" do
@my_string.should have(66).characters
end
it "should be able to split on the . character" do
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
Expand Down
Binary file removed week2/.DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?

An array is an indexed collection of object references. A hash is also an indexed collection of object references, but with an array you index integers and in a hash you index any object type but the object is indexed with a key value.

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

I would use a hash over an array when I wanted the indices for the objects to be more memorable. I would use an array when the ordering of the objects matter because hashes don't have an order and arrays do.

3. What is a module? Enumerable is a built in Ruby module, what is it?

A module is a collection of methods and constants. Enumerable is a module that allows your

4. Can you inherit more than one thing in Ruby? How could you get around this problem?

Ruby is a single inheritance language. However, Ruby can use a mixin to provide "multiple-inheritence-like" capability.

5. What is the difference between a Module and a Class?

Modules are collections of variables and/or methods, but are not instances of the class Class. They can however behave like a superclass by being added to a class.
21 changes: 21 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module SimonSays
def echo(string)
string
end

def shout(string)
string.upcase
end

def repeat(string, n=2)
[string] * n * ' ' #So may variable string is now an array... I am terrible at naming ><
end

def start_of_word(string, n)
string[0..n-1]
end

def first_word(string, n=1)
string.split(/ /)[0]
end
end
18 changes: 18 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Calculator

def sum input
input.inject(0, :+)
end

def multiply *input
input.flatten.inject(:*)
end

def pow input1, input2
input1**input2
end

def fac input
(1..input).inject(:*) || 1
end
end
10 changes: 10 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ Please Read:

1. What is a symbol?

A symbol is an immutable representation of a string.

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

A string is mutable, a symbol is not.

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

A block is code that is called with curly braces or do ... end.

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

A block can be passed to a method with yield or it can be instantiated with an ampersand.

5. Where would you use regular expressions?

A regular express is useful for matching text against the contents of a string, such as when verifying the contents of a string or substituting pieces of the string.
10 changes: 10 additions & 0 deletions week4/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?

Ruby reads files through the File class, with the command File.open("file", "r") {|n| n.gets}

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

File.open("output", "w") {|n| n.puts "Hello World!"}

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

Objects in the directory class represent file directories on the computer, and it is used to list those directories and see thecontents.
4. What is an IO object?

Your mom... is not an IO object. An IO object is an object of the class IO and is a representation of a source file, which allows for external communication with computer resources.

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

Rake is Ruby make. It is for writing automation scripts and making dependecies, as well as grouping together like-tasks, kind of like you would with a module. A rank task is merely the set of commands Ruby uses to do those things I just mentioned.
5 changes: 5 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Worker
def self.work i = 1
i.times.inject(0){yield}
end
end
36 changes: 36 additions & 0 deletions week4/homework/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "#{File.dirname(__FILE__)}/worker"

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
5 changes: 5 additions & 0 deletions week5/exercises/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
task :outputs_name do
File.open("names").readlines.each do |line|
puts line
end
end
26 changes: 26 additions & 0 deletions week7/MagicNineBall/Bin/magic_nine_ball.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby

require 'magic_nine_ball'

class MagicNineBall

print "What is your question "
question = gets.chomp
array = ["Yes, in due time.",
"My sources say no.",
"Definitely not.",
"Yes.",
"You will have to wait.",
"I have my doubts.",
"Outlook so so.",
"Looks good to me!",
"Who knows?",
"Looking good!",
"Probably.",
"Are you kidding?",
"Go for it!",
"Don't bet on it.",
"Forget about it."]
@array = array
puts @array.sample
end
24 changes: 24 additions & 0 deletions week7/MagicNineBall/Lib/magicnineball.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby

class MagicNineBall

print "What is your question "
question = gets.chomp
array = ["Yes, in due time.",
"My sources say no.",
"Definitely not.",
"Yes.",
"You will have to wait.",
"I have my doubts.",
"Outlook so so.",
"Looks good to me!",
"Who knows?",
"Looking good!",
"Probably.",
"Are you kidding?",
"Go for it!",
"Don't bet on it.",
"Forget about it."]
@array = array
puts @array.sample
end
Binary file added week7/MagicNineBall/magic_nine_ball-0.0.0.gem
Binary file not shown.
Binary file added week7/MagicNineBall/magic_nine_ball-0.0.1.gem
Binary file not shown.
Binary file added week7/MagicNineBall/magic_nine_ball-0.0.3.gem
Binary file not shown.
13 changes: 13 additions & 0 deletions week7/MagicNineBall/magic_nine_ball.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Gem::Specification.new do |s|
s.name = "magic_nine_ball"
s.version = "0.0.3"
s.date = '2013-11-10'
s.summary = "This gem predicts the future"
s.description = "Type in your question to get your fortune!"
s.authors = ["Thomas Osborn"]
s.email = '[email protected]'
s.homepage = 'http://rubygems.org/gems/magic_eight_ball'
s.files = ["lib/MagicNineBall.rb"]
s.licenses = ['MIT']
s.executables << 'magic_nine_ball.rb'
end
9 changes: 9 additions & 0 deletions week7/MagicNineBall/magic_nine_ball_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# magic_nine_ball_spec.rb
require 'magicnineball'

describe MagicNineBall do
it "makes sure magicnineball is not nil" do
@magicnineball = MagicNineBall.new
@magicnineball.nil?
end
end
Loading