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

week 2 materials #2

Merged
merged 1 commit into from
Oct 14, 2014
Merged
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
10 changes: 10 additions & 0 deletions week2/class_materials/resources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Ruby Docs: http://www.ruby-doc.org/core-1.9.3/String.html
Pragmatic Programmers Guide: http://pragprog.com/book/ruby3/programming-ruby-1-9 (at the bottom is the link to the extending Ruby pdf I mentioned)

Travis CI (where open source projects are tested): https://travis-ci.org
grb: https://github.com/jinzhu/grb
The Ruby ToolBox: https://www.ruby-toolbox.com/

my alias for rspec:
alias rspec="rspec --color --format documentation"
Binary file added week2/class_materials/week2.key
Binary file not shown.
Binary file added week2/class_materials/week2.pdf
Binary file not shown.
Empty file added week2/examples/.keep
Empty file.
17 changes: 17 additions & 0 deletions week2/exercises/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Book
attr_accessor :title
attr_reader :page_count

@@book_count = 0

def self.book_count
@@book_count
end

def initialize title = "Not Set", page_count = 0
@@book_count += 1
@page_count = page_count
@title = title
end

end
49 changes: 49 additions & 0 deletions week2/exercises/book_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require_relative 'book'
require_relative '../../spec_helper'

describe Book do

context "::book_count" do

it "should count how many books have been created" do
Book.new
Book.new
Book.new
Book.book_count.should eq 3
end

end

context "::new" do

it "should set some defaults" do
Book.new.title.should eq "Not Set"
end

it "should allow us to set the page count" do
book = Book.new "Harry Potter", 5
book.page_count.should eq 5
end

end

context "#title" do

before :each do
@book = Book.new
end

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

it "should allow me to set the title" do
@book.title = "Snow Crash"
@book.title.should eq "Snow Crash"
end



end

end
10 changes: 10 additions & 0 deletions week2/exercises/mad_libs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
puts "Please enter a noun"
noun = gets.chomp
puts "Please enter an adjective"
adjective = gets.chomp
puts "Please enter a past tense action verb"
verb_past_tense = gets.chomp
puts "What does the #{noun} say?"
says = gets.chomp
story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}"
puts story
13 changes: 13 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Please Read The Chapters on:
Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

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

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?

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

5. What is the difference between a Module and a Class?
48 changes: 48 additions & 0 deletions week2/homework/simon_says_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Hint: require needs to be able to find this file to load it
require_relative "simon_says.rb"
require_relative '../../spec_helper'

describe SimonSays do
include SimonSays # Hint: Inclusion is different than SimonSays.new (read about modules)

# Hint: We are just calling methods, we are not passing a message to a SimonSays object.
it "should echo hello" do
echo("hello").should == "hello"
end

it "should echo bye" do
echo("bye").should == "bye"
end

it "should shout hello" do
shout("hello").should == "HELLO"
end

it "should shout multiple words" do
shout("hello world").should == "HELLO WORLD"
end

it "should repeat" do
repeat("hello").should == "hello hello"
end

it "should repeat a number of times" do
repeat("hello", 3).should == "hello hello hello"
end

it "should return the first letter" do
start_of_word("hello", 1).should == "h"
end

it "should return the first two letters" do
start_of_word("Bob", 2).should == "Bo"
end

it "should tell us the first word of 'Hello World' is 'Hello'" do
first_word("Hello World").should == "Hello"
end

it "should tell us the first word of 'oh dear' is 'oh'" do
first_word("oh dear").should == "oh"
end
end