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

Jack1 #110

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.DS_Store
.*.swp
.*.un~

39 changes: 0 additions & 39 deletions midterm/instructions_and_questions.txt

This file was deleted.

74 changes: 0 additions & 74 deletions midterm/mid_term_spec.rb

This file was deleted.

18 changes: 0 additions & 18 deletions midterm/wish_list_spec.rb

This file was deleted.

16 changes: 16 additions & 0 deletions week1/homework/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Please read:
Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object? - An object is an instance of a class. For example: “Back in Black” could be an object of the class “albums”

2. What is a variable? A variable is a reference to an object and holds values.

3. What is the difference between an object and a class? An object is an individual instance of a class. Objects are the data members of classes. Objects are also referred to as class instances.

4. What is a String? Strings are sequence of characters stored in a variable. Strings can be printable characters or binary data.

5. What are three messages that I can send to a string object? Hint: think methods: split, chomp and swapcase.

6. What are two ways of defining a String literal? Bonus: What is the difference between them?
You can define them using single or double quotes. Double quotes gives you a lot more options for using escape sequences
4 changes: 4 additions & 0 deletions week1/homework/lor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
....

Finished in 0.00227 seconds
4 examples, 0 failures
19 changes: 14 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,23 @@
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 deine empty string" do
@my_string.should_not be_empty
end
it "should be able to count the charaters" do
@my_string.should have(@my_string.length).characters
end
# ruby count string characters
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
result.should have(2).items
# ruby split code
#
#result = @my_string.split(.)
#pending
#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"))'
# # encoding string
# @my_string.encoding.should eq (Encoding.find("("UTF-8").valid_encoding?
end
end
end
Expand Down
Empty file added week2/homework/lor
Empty file.
26 changes: 19 additions & 7 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
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?
A hashes are more flexible as you can index them using symbols, strings and regular expressions as opposed to just integers.



2. When would you use an Array over a Hash and vice versa?
I would use a hash if i needed to store the list using a key word or string for each variable. An array is simpler to set up and
simply uses an integer as it's key value pair based on the order that the variables are in the array. Arrays are easier to manipulate using integers.



3. What is a module? Enumerable is a built in Ruby module, what is it? A module is a collection of methods, constants and classes.
Ennumberable is a built in mixin which provides various capabilities of sorting data.



4. Can you inherit more than one thing in Ruby? How could you get around this problem? Ruby is a single inheritance language.
Mixins can be used within ruby classes to get around this limitation.


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? A module can't have instances. A module is a chunk of reusable
code in it's own ruby program that i can call from another program using "requires". Modules can contain functions and/or variables.
Classes are like modules with the exception that you can use them to create new instances of each other without them interfering with each other.

5. What is the difference between a Module and a Class?
22 changes: 22 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module SimonSays
def echo(simon)
simon
end

def shout(simon)
simon.upcase
end

def start_of_word(simon,last)
simon[0...last]
end

def first_word(simon)
simon.split.first
end

def repeat simon, n=2
results = (simon + ' ') * n
results.chop
end
end
5 changes: 3 additions & 2 deletions week2/homework/simon_says_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
require "./simon_says.rb"

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

include SimonSays

# 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"
Expand Down
Binary file added week3/exercises/.book.rb.un~
Binary file not shown.
Binary file added week3/exercises/.book_spec.rb.un~
Binary file not shown.
Binary file added week3/exercises/.human.rb.un~
Binary file not shown.
Binary file added week3/exercises/.some_file.un~
Binary file not shown.
Binary file added week3/exercises/.vampire.rb.un~
Binary file not shown.
Binary file added week3/exercises/.zombie.rb.un~
Binary file not shown.
24 changes: 21 additions & 3 deletions week3/exercises/book.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
$global_hello = "hi there"

module Library

class Book

def pages

attr_accessor :pages, :title

@@library_count = 0

def self.library_count
@@library_count
end

def initialize pages, title="N/A"
@pages = pages
@title = title
@@library_count += 1
end


end
def happy
$global_hello = "hello"
"There are #{@pages} happy pages in the book"
end
32 changes: 26 additions & 6 deletions week3/exercises/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
require './book.rb'

describe Book do

it "should have a pages" do
book = Book.new
book.should respond_to "pages"
end

end
before :each do
@book = Book.new 542, "Programming Ruby"
end

context "::library_count" do
it "should tell us how many books are in our library" do
Book.library_count.should eq 542
end
end

context "#pages" do
it "should have a pages" do
@book.should respond_to "pages"
end

it "should allow us to get the number of pages" do
@book.pages.should eq 542
end
end

context "#title" do
it "should let us read the title" do
@book.title.should eq "Programming Ruby"
end
end
end
6 changes: 6 additions & 0 deletions week3/exercises/human.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'named_thing'

class Human
include NamedThing
include OtherThing
end
3 changes: 3 additions & 0 deletions week3/exercises/some_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3 4
5 6
7 8
5 changes: 5 additions & 0 deletions week3/exercises/vampire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ class Vampire < Monster
def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites])
super(noc,legs,name,vul,dangers)
end

def bite! human

end

end
8 changes: 8 additions & 0 deletions week3/exercises/zombie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'named_thing'
class Zombie
include NamedThing

def say_name
"uuurrrgggghhhh #{@name}"
end
end
Binary file added week3/homework/.calculator.rb.swp
Binary file not shown.
Binary file added week3/homework/.calculator.rb.un~
Binary file not shown.
Binary file added week3/homework/.calculator_spec.rb.un~
Binary file not shown.
Binary file added week3/homework/.questions.txt.un~
Binary file not shown.
26 changes: 26 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Calculator

def sum input

total = 0
input.each do |i|
total += i
end
total

input.reduce 0, :+
end

def multiply *ary_nums
ary_nums.flatten.inject :*
end

def pow base, exp
base**exp
end

def fac n
multiply (1..n).to_a
end

end
2 changes: 1 addition & 1 deletion week3/homework/calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "#{File.dirname(__FILE__)}/calculator"
require './calculator.rb'

describe Calculator do

Expand Down
Loading