Skip to content

Commit 82d44b8

Browse files
committed
Merge pull request #2 from UWE-Ruby/master
week 2 materials
2 parents 9677709 + d15be6b commit 82d44b8

File tree

9 files changed

+147
-0
lines changed

9 files changed

+147
-0
lines changed

week2/class_materials/resources.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Ruby Docs: http://www.ruby-doc.org/core-1.9.3/String.html
3+
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)
4+
5+
Travis CI (where open source projects are tested): https://travis-ci.org
6+
grb: https://github.com/jinzhu/grb
7+
The Ruby ToolBox: https://www.ruby-toolbox.com/
8+
9+
my alias for rspec:
10+
alias rspec="rspec --color --format documentation"

week2/class_materials/week2.key

856 KB
Binary file not shown.

week2/class_materials/week2.pdf

1.04 MB
Binary file not shown.

week2/examples/.keep

Whitespace-only changes.

week2/exercises/book.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Book
2+
attr_accessor :title
3+
attr_reader :page_count
4+
5+
@@book_count = 0
6+
7+
def self.book_count
8+
@@book_count
9+
end
10+
11+
def initialize title = "Not Set", page_count = 0
12+
@@book_count += 1
13+
@page_count = page_count
14+
@title = title
15+
end
16+
17+
end

week2/exercises/book_spec.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require_relative 'book'
2+
require_relative '../../spec_helper'
3+
4+
describe Book do
5+
6+
context "::book_count" do
7+
8+
it "should count how many books have been created" do
9+
Book.new
10+
Book.new
11+
Book.new
12+
Book.book_count.should eq 3
13+
end
14+
15+
end
16+
17+
context "::new" do
18+
19+
it "should set some defaults" do
20+
Book.new.title.should eq "Not Set"
21+
end
22+
23+
it "should allow us to set the page count" do
24+
book = Book.new "Harry Potter", 5
25+
book.page_count.should eq 5
26+
end
27+
28+
end
29+
30+
context "#title" do
31+
32+
before :each do
33+
@book = Book.new
34+
end
35+
36+
it "should have a title" do
37+
@book.should respond_to "title"
38+
end
39+
40+
it "should allow me to set the title" do
41+
@book.title = "Snow Crash"
42+
@book.title.should eq "Snow Crash"
43+
end
44+
45+
46+
47+
end
48+
49+
end

week2/exercises/mad_libs.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
puts "Please enter a noun"
2+
noun = gets.chomp
3+
puts "Please enter an adjective"
4+
adjective = gets.chomp
5+
puts "Please enter a past tense action verb"
6+
verb_past_tense = gets.chomp
7+
puts "What does the #{noun} say?"
8+
says = gets.chomp
9+
story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}"
10+
puts story

week2/homework/questions.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Please Read The Chapters on:
2+
Containers, Blocks, and Iterators
3+
Sharing Functionality: Inheritance, Modules, and Mixins
4+
5+
1. What is the difference between a Hash and an Array?
6+
7+
2. When would you use an Array over a Hash and vice versa?
8+
9+
3. What is a module? Enumerable is a built in Ruby module, what is it?
10+
11+
4. Can you inherit more than one thing in Ruby? How could you get around this problem?
12+
13+
5. What is the difference between a Module and a Class?

week2/homework/simon_says_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Hint: require needs to be able to find this file to load it
2+
require_relative "simon_says.rb"
3+
require_relative '../../spec_helper'
4+
5+
describe SimonSays do
6+
include SimonSays # Hint: Inclusion is different than SimonSays.new (read about modules)
7+
8+
# Hint: We are just calling methods, we are not passing a message to a SimonSays object.
9+
it "should echo hello" do
10+
echo("hello").should == "hello"
11+
end
12+
13+
it "should echo bye" do
14+
echo("bye").should == "bye"
15+
end
16+
17+
it "should shout hello" do
18+
shout("hello").should == "HELLO"
19+
end
20+
21+
it "should shout multiple words" do
22+
shout("hello world").should == "HELLO WORLD"
23+
end
24+
25+
it "should repeat" do
26+
repeat("hello").should == "hello hello"
27+
end
28+
29+
it "should repeat a number of times" do
30+
repeat("hello", 3).should == "hello hello hello"
31+
end
32+
33+
it "should return the first letter" do
34+
start_of_word("hello", 1).should == "h"
35+
end
36+
37+
it "should return the first two letters" do
38+
start_of_word("Bob", 2).should == "Bo"
39+
end
40+
41+
it "should tell us the first word of 'Hello World' is 'Hello'" do
42+
first_word("Hello World").should == "Hello"
43+
end
44+
45+
it "should tell us the first word of 'oh dear' is 'oh'" do
46+
first_word("oh dear").should == "oh"
47+
end
48+
end

0 commit comments

Comments
 (0)