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

scott 06 final #133

Open
wants to merge 30 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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Directories
scratch/

# RBEnv
.rbenv_gemsets
.ruby-gemset

# OSX
.DS_Store?
1 change: 1 addition & 0 deletions .rbenv-gemsets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SD_RubyFall
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format nested --color
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SD_RubyFall
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0-p247
48 changes: 0 additions & 48 deletions .rvmrc

This file was deleted.

11 changes: 11 additions & 0 deletions week1/class_materials/name_printer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe "NamePrinter Application" do

context "When Renee is logged in" do

it "should say Renee" do

"Renee".should eq "Renee"

end
end
end
17 changes: 9 additions & 8 deletions week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
# true.should == false

# Lesson: It's easy to write bad tests.

end

it "should count the characters in my name" do
Expand All @@ -69,24 +68,26 @@
it "should check how to spell my name" do
"Renée".should include("ée")
end

end

context "Examples for in-class test exploration" do
it "should know order of operations" do
# Fix the Failing Test
# Order of Operations is Please Excuse My Dear Aunt Sally:
# Parentheses, Exponents, Multiplication, Division, Addition, Subtraction
(1+2-5*6/2).should eq -13
(1+2-5*6/2).should eq -12
end

it "should count the characters in your name" do
pending
"Scott".should have(5).characters
end

it "should check basic math"

it "should check basic spelling"
it "should check basic math" do
(5*5).should eq 25
end

it "should check basic spelling" do
"Scott".should include("Scott")
end
end

end
13 changes: 13 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
In Ruby, everything you manipulate and the results of those manipulations is an object.

2. What is a variable?
Variables keep track of objects by holding a referance to that object. They are the container in which values are stored.

3. What is the difference between an object and a class?
In Ruby a class is a category of things that are represented in code. A class is a combination of state and methods.
An object is everything you manipulate and the results of those manipulations.
So, objects are instances of classes which are themselves objects.

4. What is a String?
A string is a sequence of charaters.

5. What are three messages that I can send to a string object? Hint: think methods
There are more than a hundred methods in the String class. Three listed from the text are
String#split - break a line into fields
String#scan - convert time from mm:ss to seconds
String#chomp - removes newline character

6. What are two ways of defining a String literal? Bonus: What is the difference between the two?
1 - with single quotes 'this is a string'
2 - with double quotes "this is a string"
difference - use double quotes for string interpolation (for when you want to imbed a variable in the string) and for greater character subsitution options.
21 changes: 15 additions & 6 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# encoding: utf-8
# encoding: UTF-8

# RubyFall2013 Scott Dodson "06"

# Please make these examples all pass
# You will need to change the 3 pending tests
Expand All @@ -7,19 +9,26 @@
# The two tests with the pending keyword, require some ruby code to be written
# (Hint: You should do the reading on Strings first)


class String
def items
split('.')
end
end

describe String do
context "When a string is defined" do
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 count the charaters" do
@my_string.should have(66).characters #do something with @my_string here
end
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
result.should have(2).items
@my_string.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
20 changes: 20 additions & 0 deletions week10/shoes_timer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'shoes'
Shoes.app :height => 250, :width => 350 do
background ask_color('Pick your BKG')
stack :margin => 10 do
button "Start" do
@time = Time.now
@label.replace "Stop watch started at #@time"
end
button "Stop" do
@label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed."
end
@label = para "Press ", strong("start"), " to begin timing."

button "Reset" do
@label.replace "Press ", strong("start"), " to begin timing."
@time = nil
end

end
end
Binary file removed week2/.DS_Store
Binary file not shown.
7 changes: 6 additions & 1 deletion week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
A Hash is an index of objects and an Array is an index of integers.

2. When would you use an Array over a Hash and vice versa?
Use an Array when there is a given order to data stored and use a Hash when the name or key is more suited as order doesn't matter.

3. What is a module? Enumerable is a built in Ruby module, what is it?
A module generally contains a collection of methods for use by other classes. In Ruby, Enumerable is a collection of classes with traversing and sorting methods and can sort.

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

No you cannot, it is not allowed in Ruby. A Ruby object can have many ancesters and an object can include modules and subclasses to extend funcionality.

5. What is the difference between a Module and a Class?
A class can produce an object and a Module cannot, a module is a collection of methods for use by many classes.
37 changes: 37 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module SimonSays

#define methods echo, shout, repeat, start_of_word and first_word

#echo - echo("string") repeat back a string
def echo(string)
string
end

#shout - shout("string") convert a string to caps
def shout(string)
string.upcase
end

#repeat - repeat("string", number) repeat a string number times
def repeat(string, n=2)
([string]*n).join(' ')
end

#start_of_word - start_of_word("string", number) return number characters of string
def start_of_word(string, number)
string[0,number]
end

#first_word - first_word("multi word string") return first word of string
def first_word(string)
#string.split(' ', 0) [0]
string.split(/ /, 0) [0]
end

#any_word - any_word("multi word string", number) return number word from string
def any_word(string, number)
# string.split(' ', 0) [number]
string.split(/ /, 0) [number]
end

end
22 changes: 22 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Calculator

def sum(numbers)
# numbers.inject(0){|sum, a| sum +a}
numbers.inject(0, :+) #from class
end

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

def pow(base, power)
base**power
end

def fac(n)
return 1 if n.zero?
1.upto(n).inject(:*)
# (1..n).inject(1, :+) ??
end

end
7 changes: 6 additions & 1 deletion week3/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
Please Read:
- Chapter 6 Standard Types
- Review Blocks
- Review Blocks (done)
- Chapter 7 Regular Expressions
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants

1. What is a symbol?
A symbol is an identifier which cresponds to a string. It is preceded by a :.

2. What is the difference between a symbol and a string?
A symbol is not mutable and is stored in the same object id... they are faster to work with than strings.

3. What is a block and how do I call a block?
a block a chuck of code enclosed in curly braces or the keywords 'do' and 'end'. To call a block a block use an iterator. Common iterators are 'each', 'collect/map' and 'find'. (loc 2418 - inject interator from Enumerable... work through examples)

4. How do I pass a block to a method? What is the method signature?
You pass a block to a method using 'yield' or by passing the last element in the method signature with an &. The method signature is the method name... the content of the line following 'def'.

5. Where would you use regular expressions?
I use regular expressions when I want to find a pattern within a set of strings.
33 changes: 33 additions & 0 deletions week4/exercises/even_number_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

# - Write a passing rspec file called even_number_spec.rb that tests a class called EvenNumber.
# - The EvenNumber class should:
# - Only allow even numbers
# - Get the next even number
# - Compare even numbers
# - Generate a range of even numbers

require './even_number.rb'

describe EvenNumberR do

it "Only allows even numbers" do
result = EvenNumberR.only_even(2)
result.should = 2
end
=begin
it "gets the next even number" do
pending "something" do
end
end

it "compares even numbers" do
pending "something" do
end
end

it "Generates a range of even numbers" do
pending "something" do
end
end
=end
end
5 changes: 5 additions & 0 deletions week4/exercises/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Worker
def self.work(number=1)
number.times.inject(nil){yield}
end
end
11 changes: 10 additions & 1 deletion week4/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
Please Read:
Chapter 10 Basic Input and Output
Chapter 11 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
There are a number of methods for opening files relevant to their content, one such method is File.open.

2. How would you output "Hello World!" to a file called my_output.txt?
File.open("my_output.txt", "w"){|file| file.puts "Wello World!"}

3. What is the Directory class and what is it used for?
"Objects of class Dir are directory streams representing directories in the underlying file system. They provide a variety of ways to list directories and their contents."

4. What is an IO object?
"An IO Object is a bidirectional channel between a Ruby program and some external resource."

5. What is rake and what is it used for? What is a rake task?
Rake is a Ruby build program, it is an internal Domain Specific Language (DSL) which uses Ruby. Rake is used for specifying tasks with prerequisites, it is simiar to 'make'. A Rake task conists of a definiton, list of prerequisites and a body which performs some operation.
7 changes: 7 additions & 0 deletions week5/exercises/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
task :readlines do
File.open("names").each_line {|line| puts line}
end

task :makedir do
Dir.mkdir("class")
end
Loading