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

week 9 gem uploaded - jonas haskins #119

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e15fe96
finished the homework!
Oct 15, 2013
7e6e8be
my homework
Oct 16, 2013
8c7cb8c
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Oct 16, 2013
8f4539f
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
Oct 16, 2013
1dfb52e
Finished the homework questions, and the simon_says.rb module for hom…
sanojsniksah Oct 22, 2013
99b604b
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Oct 23, 2013
433e2fe
my book exe
sanojsniksah Oct 24, 2013
3d0172c
spec file.
sanojsniksah Oct 24, 2013
0fc7874
exercises and stuff ...
sanojsniksah Oct 24, 2013
a2085b7
homework ! jonas haskins week 3
sanojsniksah Oct 30, 2013
2d2a8d3
Merge github.com:UWE-Ruby/RubyFall2013
sanojsniksah Nov 5, 2013
72c3def
Merge github.com:UWE-Ruby/RubyFall2013
sanojsniksah Nov 6, 2013
a52c98b
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Nov 11, 2013
24c4b92
Initial commit
sanojsniksah Nov 11, 2013
a909850
Created the new depo and added the instructions to get started.
sanojsniksah Nov 11, 2013
24496d5
first draft of working even numbers and even numberes spec.
sanojsniksah Nov 12, 2013
65dc743
Merge branch 'master' of github.com:sanojsniksah/jonashaskins_midterm
sanojsniksah Nov 12, 2013
761d1b1
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Nov 14, 2013
8816f5d
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Nov 20, 2013
978f2c2
homework for week 7
sanojsniksah Nov 27, 2013
25791bd
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Dec 3, 2013
767bfa4
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Dec 3, 2013
3e357cf
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah Dec 5, 2013
2b2f5ae
added all these goodies and the .travis.yml
sanojsniksah Dec 6, 2013
d0378b1
fixed a issue with .travis.yml
sanojsniksah Dec 6, 2013
e2d9429
added my gem.
sanojsniksah Dec 10, 2013
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
Binary file added .DS_Store
Binary file not shown.
48 changes: 0 additions & 48 deletions .rvmrc

This file was deleted.

10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: ruby
rvm:
- "1.8.7"
- "1.9.2"
- "1.9.3"
- jruby-18mode # JRuby in 1.8 mode
- jruby-19mode # JRuby in 1.9 mode
- rbx-18mode
# uncomment this line if your project needs to run something other than `rake`:
# script: bundle exec rspec spec
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
RubyFall2013
============

@@ -57,7 +58,16 @@ Week 10
* Final due!
* Project due!
* Interesting Stuff
<<<<<<< HEAD
=======
jonashaskins_midterm
====================

keeps my midter
>>>>>>> a909850fc83ae544cc25011759e2c6217f254bb5
=======


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/UWE-Ruby/rubyfall2013/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

>>>>>>> 8b3b197baa14a59c207aca832acf7ce570e9e099
File renamed without changes.
File renamed without changes.
Empty file added test
Empty file.
Binary file added week1/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions week1/class_materials/name_printer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe "NamePrinter Application" do

context "When Somethings Happens When I'm Logged In" do
it "should say Something" do
"Something".should eq "Something"
end
end
end
30 changes: 22 additions & 8 deletions week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -43,11 +43,14 @@

# When this example fails,
# it will show "expected" as 2, and "actual" as 1
1.should eq 2
1.should eq 1

end

it "supports placeholder examples that lack code (like this one)"

# jhjh
it "supports placeholder examples that lack code (like this one)" do
1.should eq 1
end

it "requires that examples use expectations (like #should) to work properly" do

@@ -71,21 +74,32 @@
end

end

## JHJH added class tests
context "When Somethings Happens When I'm Logged In" do
it "should say Something" do
"Something".should eq "Something"
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

context "Count my name" do
it "should count the characters in your name" do
"Jonas".should have(5).characters
end
end

it "should check basic math"
it "should check basic math"

it "should check basic spelling"
it "should check basic spelling"

end

32 changes: 32 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
Please read:
Chapter 3 Classes, Objects, and Variables

p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
a instance of a class.

2. What is a variable?
a reference to a object

3. What is the difference between an object and a class?
a class is a combination of state and methods. an object is a instance of that class ( class instance ).


4. What is a String?
A sequence of characters.

5. What are three messages that I can send to a string object? Hint: think methods
chomp, count, delete, empty? , length, upcase, downcase, split, squeeze! ... woah there are alot.


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

single or double quotation marks.

single quotes 'foo', foo becomes the value.
For Double quotes, "foo\nbar" ruby looks for substitutions, interpolation "#{foo}" and escape sequences "Foo \nBar"

also %q ( single quotes ), %Q ( double quotes )

%q/foo bar/
%Q!oh no #{crap}!

you can choose a delimiter.

Finally here documents.

string = << HERE
some kinda text
about something
i forgot what
HERE



check them in and send a pull request !!
29 changes: 25 additions & 4 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -12,14 +12,35 @@
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
result = @my_string.count @my_string
result.should eq 66
#puts "Count is #{result}"

# These work to
# white space are characters to
# size = @my_string.size
# size.should eq 66
# puts "Size is #{size}"

# delete the white spaces !
# @new_string = @my_string.delete(' ')
# size = @new_string.size
# size.should eq 55
# puts "Size is #{size}"

end

it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
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"))'
#pending 'helpful hint: should eq (Encoding.find("UTF-8"))'
"#{@my_string.encoding}".should eq "UTF-8"
#puts "Encoding of #{@my_string.inspect} is #{@my_string.encoding}"


end
end
end
26 changes: 26 additions & 0 deletions week1/homework/strings_and_rspec_spec_org.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# encoding: utf-8

# Please make these examples all pass
# You will need to change the 3 pending tests
# You will need to write a passing test for the first example
# (Hint: If you need help refer to the in-class exercises)
# The two tests with the pending keyword, require some ruby code to be written
# (Hint: You should do the reading on Strings first)

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 split on the . charater" do
pending
result = #do something with @my_string here
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"))'
end
end
end

9 changes: 9 additions & 0 deletions week2/count_frequency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def count_frequency(word_list)
counts = Hash.new(0)
for word in word_list
counts[word] += 1
end
counts
end

p count_frequency(["sparky", "the", "cat", "sat", "on", "the", "mat"])
32 changes: 31 additions & 1 deletion week2/exercises/book.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
class Book
<<<<<<< HEAD
attr_accessor :title
attr_reader :page_count
#attr_reader :title #reader only ?
@@book_count = 0

#self. = class level
def self.book.count
## @@ = class level varable
@@book_count
end

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

def test
@test = "Hellow!"
end

def out_put_test
puts @test
puts @@book_count
end

end
=======
attr_accessor :title
attr_reader :page_count

@@ -24,4 +53,5 @@ def out_put_test
puts @@book_count
end

end
end
>>>>>>> 4706ad52545867a37a0e21a394c5e1103020fe67
29 changes: 28 additions & 1 deletion week2/exercises/book_spec.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,32 @@

describe Book do

<<<<<<< HEAD
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



it "should should set some defaults" do
@book.new
end
it "should allow me to set the title" do
@boot.title = "Harry Potter"
@book.title.should eq "Harry Potter"


it "should return the page count" do
@book.page_count.should eq "Page count is 200"
end
end
=======

context "::book_count" do

@@ -46,4 +72,5 @@

end

end
end
>>>>>>> 4706ad52545867a37a0e21a394c5e1103020fe67
8 changes: 4 additions & 4 deletions week2/exercises/mad_libs.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
puts "Please enter a noun"
print "Please enter a noun : "
noun = gets.chomp
puts "Please enter an adjective"
print "Please enter an adjective : "
adjective = gets.chomp
puts "Please enter a past tense action verb"
print "Please enter a past tense action verb : "
verb_past_tense = gets.chomp
puts "What does the #{noun} say?"
print "What does the #{noun} say? : "
says = gets.chomp
story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}"
puts story
3 changes: 3 additions & 0 deletions week2/exercises/spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe Book do

context
27 changes: 26 additions & 1 deletion week2/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -3,11 +3,36 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
An array is integer indexed collection of objects.
array_example[0] is the first object in the array.

A hash is also a indexed collection of object references, except
in that it can be indexed with objects of any types : strings,symbols, ect.. integers also.
but arrays are just indexed by integers.

my_hash = { 'black' => 'knight' }

black (key) referes to knight ( value )

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?
I would use a hash for ordered items, and for efficent search/lookup
The key index will result in the value(s). Also to count frequencys. Using they
key and incrementing the value as the key was counted.

An array would work great if I needed to store a collection of objects and the iterate
over it. If I needed a que or a stack i'd use a array. Or if i needed to split a string,
or read in variable input to a method.

3. What is a module?
a way of grouping together methods, classes and constants. Modules define a namespace.

Enumerable is a built in Ruby module, what is it?
Its a mixin. collection classes, traversal and searching methods and the ability to sort!

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
No, Ruby is a single inheritance language. The child can only inherit from the parent.
You can get around the problem by using mixins, which provide a controlled multiple-inheritance like capability!

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

def shout(shouts)
@shouts = shouts
@shouts.upcase
end

def repeat(word, *times)
@word = word
@times = times[0]
if @times == nil
@times = 2
end
@word = "#{@word} " * @times
@word.rstrip
end

def start_of_word(word, number)
a = word.split(//)
number = number - 1
b = a[0..number]
b.join
end

def first_word(word)
a = word.split(/ /)
a[0]
end

end

# Question .. is it correct to use instance variables here as in for
# echo/shout/repeat methods or better ( more ruby?? ) to use
# as in start_or_word and first_word ??

20 changes: 20 additions & 0 deletions week2/tester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative 'count_frequency'
require 'test/unit'

class TestCountFrequency < Test::Unit::TestCase
def test_empty_list
assert_equal({}, count_frequency([]))
end
def test_single_word
assert_equal({"cat" => 1}, count_frequency(["cat"]))
end
def test_two_different_words
assert_equal({"cat" => 1, "sat" => 1}, count_frequency(["cat", "sat"]))
end
def test_two_words_with_adjacent_repeat
assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "cat", "sat"]))
end
def test_two_words_with_non_adjacent_repeat
assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "sat", "cat"]))
end
end
5 changes: 5 additions & 0 deletions week2/words_from_strings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def words_from_string(string)
string.downcase.scan(/[\w']+/)
end

p words_from_string("But I didn't inhale, he said (emphatically)")
27 changes: 27 additions & 0 deletions week3/exercises/answers.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1.9.3-p392 :001 > load 'monsters.rb'
=> true
1.9.3-p392 :002 > $monsters.count{|m| m[:nocturnal]}
=> 2
1.9.3-p392 :005 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]}
=> ["Vampire", "Werewolf"]

1.9.3-p392 :007 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]}
=> ["Vampire", "Werewolf"]

1.9.3-p392 :009 > legs = 0
=> 0

1.9.3-p392 :011 > $monsters.each{|m| legs += m[:legs]}
=> [{:name=>"Zombie", :nocturnal=>false, :dangers=>["bites", "scratches"], :vulnerabilities=>["fire", "decapitation"], :legs=>2}, {:name=>"Mummy", :nocturnal=>false, :dangers=>["bites", "scratches", "curses"], :vulnerabilities=>["fire", "decapitation", "cats"], :legs=>2}, {:name=>"Vampire", :nocturnal=>true, :dangers=>["bites", "hypnosis"], :vulnerabilities=>["wood", "decapitation", "crosses", "holy_water", "garlic", "daylight"], :legs=>2}, {:name=>"Werewolf", :nocturnal=>true, :dangers=>["bites", "scratches"], :vulnerabilities=>["silver"], :legs=>4}, {:name=>"Blob", :nocturnal=>false, :dangers=>["suffocation"], :vulnerabilities=>["CO2", "ice", "cold"], :legs=>0}]
1.9.3-p392 :012 > legs
=> 10
1

counts the legs. shorthand. adds ( sum ) numbers in the array.
$monsters.map{|m| m[:legs]}.inject(:+)



1.9.3-p392 :031 > dangers.inject(Hash.new(0)){|hist, danger| hist[danger]+=1 ;hist}
=> {["bites", "scratches"]=>2, ["bites", "scratches", "curses"]=>1, ["bites", "hypnosis"]=>1, ["suffocation"]=>1}
1
20 changes: 10 additions & 10 deletions week3/exercises/monster.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require './named_thing.rb'
class Monster

class Monsters
include NamedThing
attr_accessor :vulnerabilities, :dangers
attr_reader :nocturnal, :legs

def initialize(noc, legs, name="Monster", vul = [], dangers = [])
super(name)
@nocturnal = noc
@vlunerabilities = vul
attr_accessor :names, :legs, :dangers, :vulnerabilities, :nocturnal

def initialize legs, nocturnal, name="Monster", dangers=[], vulnerabilities=[]
@leg = legs
@nocturnal = nocturnal
@dangers = dangers
@legs = legs
@vulnerabilities = vulnerabilities
super name
end
end
end
15 changes: 0 additions & 15 deletions week3/exercises/named_thing.rb

This file was deleted.

6 changes: 4 additions & 2 deletions week3/exercises/vampire.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require './monster.rb'

class Vampire < Monster
def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites])
super(noc,legs,name,vul,dangers)

def initalize legs = 2, nocturnal = true, name = "Vampire", dangers = [:bites] , vulnerabilities = [:sunlight, :garlic]
super
end
end
20 changes: 20 additions & 0 deletions week3/homework/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# au jonas haskins
class Calculator
def sum(digits)
digits.inject 0, :+
end

def pow(v1, v2)
p = 1
v2.times{ p *= v1 }
power = p
end

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

def fac(number)
(1..number).inject(:*) || 1
end
end
9 changes: 9 additions & 0 deletions week3/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -5,11 +5,20 @@ Please Read:
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants

1. What is a symbol?
It is a object representing names and some strings inside the Ruby interpreter.
they are made by :some_name and :"string" literal syntax and by the to_sym

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

3. What is a block and how do I call a block?
a block is code between two braces or between do - end
.. a way of grouping statements.
you call a block by calling yield or calling it as a Proc.

4. How do I pass a block to a method? What is the method signature?
a.method(&block) procs an ampersand

5. Where would you use regular expressions?
if you were matching any kind of string or pattern

13 changes: 13 additions & 0 deletions week4/exercises/do_work.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module DoWork
attr_accessor :work

def initialize work
@work = work
end

#def shout_name
# @name.upcase
#end

end

8 changes: 8 additions & 0 deletions week4/exercises/foobar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

'br.retsnom/.' eriuqer

retsnoM < eripmaV ssalc

]cilrag: ,thgilnus:[ = seitilibarenluv ,]setib:[ = sregnad ,"eripmaV" = eman ,eurt = lanrutcon ,2 = sgel ezilaitini fed
repus
dne dne
11 changes: 11 additions & 0 deletions week4/exercises/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Worker
def self.work x=1
if x == 1
yield
else
x = x - 1
x += yield

end
end
end
18 changes: 18 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,25 @@ Chapter 10 Basic Input and Output
The Rake Gem: http://rake.rubyforge.org/

1. How does Ruby read files?
It uses the I from the I/O ! Input is part of the base class
IO which contains classes like File, which you would use to read in a file for example
File.open or File.read

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

3. What is the Directory class and what is it used for?
The Directory class ( Dir ) is used for representing directories
on the file system. It's used for listing directories and their contents.


4. What is an IO object?
A 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 gem, and a simple build program simmilar to make.
a rake task is a task defined by a Rakefile which contains build rules
to do a job .. ie run some ruby code.
33 changes: 33 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#class Worker
# # this is a class level method
# def self.work x=1
# if x == 1
# yield
# else
# x = x - 1
# x += yield
#
# end
# end
#end



# class anserr
#class Worker
# # this is a class level method
# def self.work n=1
# results = nil
# n.times { results = yield }
# results
# end
#end


# teachers answer
class Worker
# this is a class level method
def self.work n=1
n.times.inject(nil){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
7 changes: 7 additions & 0 deletions week4/jonas/code_timer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CodeTimer
def self.time_code n=1
start_time = Time.now
n.times { yield }
Time.now - start_time
end
end
3 changes: 3 additions & 0 deletions week4/jonas/homework.2do
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
worker_spec.rb

questions file.
38 changes: 38 additions & 0 deletions week4/jonas/timer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require './code_timer.rb'

describe CodeTimer do

it "should run our code" do
flag = false

CodeTimer.time_code do
flag = true
end

flag.should eq true

end

it "should time our code" do

Time.stub(:now).and_return(0,3)
run_time = CodeTimer.time_code do
end

run_time.should be_within(0.1).of(3.0)
end

it "should run our code mult times " do
i = 0
CodeTimer.time_code(10){ i+=1 }
i.should eq 10
end

it "should give us the average time " do
run_time = CodeTimer.time_code(10) {
sleep(1)
}
run_time.should be_within(0.1).of(1.0)
end

end
32 changes: 32 additions & 0 deletions week5/exercises/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
task :default => [:hello_world]

desc "This is the hellow worrld script"
task :eatit do
puts File.read("names")
end

task :mkdir do
Dir.mkdir("Class")
end

task : create_student_dirs => [:create_class_dir ]do
Dir.chdir('Class')
File.open("../names") do |f|
f.map{|line| Dir.mkdir line.chomp}
end
end

task : create_student_dirs => [:create_class_dir ]do
Dir.chdir('Class')
File.open("../names") do |f|
f.map{|line| Dir.mkdir line.chomp}
end
end

def file_helper(file_name)
File.open(file_name) do |f|
f.each do |line|
yield line.chomp
end
end
end
1 change: 1 addition & 0 deletions week6/sanoj
Submodule sanoj added at 434d47
26 changes: 26 additions & 0 deletions week7/exercises/features/step_definitions/converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Given(/^I have entered (\d+) into the converter$/) do |arg1|
# pending # express the regexp above with the code you wish you had
@temp
end

Given(/^I set the type to Fahrenheit$/) do
# pending # express the regexp above with the code you wish you had
@type = 'Fahrenheit'
end

When(/^I press convert$/) do

end

Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2|
#pending # express the regexp above with the code you wish you had
class Convert
def self
n = (@temp - 32) * 5 / 9
n.round(1)
end
end


end

14 changes: 14 additions & 0 deletions week7/exercises/features/step_definitions/converter2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Converter

attr_writer :type

def initalize celcius_value
@value = celcius_value.to_f
end


def convert
((@value - 32 ) * (5.0 / 9.0)).round(1)
end

end
23 changes: 23 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class PirateTranslator
attr_accessor :split


def say(what)
@what = what
end

def translate
if ( @what =~ /Hello Friend/)
@what = 'Ahoy Matey' + "/n Shiber Me Timbers You Scurvey Dogs!!"
end
end

# can't figger out how to return a array of them both?
# this isn;t right.
def speak
@arr = 'Shiber Me Timbers You Scurvey Dogs!!'
@speak_a.push("@what", "@arr")
@speak = speak.a.join(/\n /)
end
end

40 changes: 40 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class PirateTranslator
attr_accessor :split

PIRATE_WORDS = {
hello_friend: "Ahoy Matey"
}

def say(what)
@what = what
end

def translate
pirate_lookup @said + "\n Awh shiver me timbers "
end


private

def pirate_lookup said
key = said.gsub(' ' , '_').downcase
PIRATE_WORDS[key]
end



def translate
if ( @what =~ /Hello Friend/)
@what = 'Ahoy Matey'
end
end

# can't figger out how to return a array of them both?
# this isn;t right.
def speak
@arr = 'Shiber Me Timbers You Scurvey Dogs!!'
@speak_a.push("@what", "@arr")
@speak = speak.a.join(/\n /)
end
end

1 change: 1 addition & 0 deletions week7/homework/features/step_definitions/pirate_steps.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@

Letgoandhaul /^it prints out '(.+)'$/ do |arg|
@result.split("\n ").first.should == arg
puts "#{arg}"
end

Letgoandhaul /^it also prints '(.+)'$/ do |arg|
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##
23 changes: 23 additions & 0 deletions week7/homework/questions.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,30 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming

Questions:
1. What is method_missing and how can it be used?
it's a method, called method_missing.

it can by used to intercept the use of a undefined method and handle it.
you can also use it to intercept all the calls to methods, but only handle
some of them ( glob? )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good.



2. What is and Eigenclass and what is it used for? Where Do Singleton methods live?
A eigenclass is a hidden class associated with each specific instance of another class..

Singleton methods are specific to a single object.
They are defined on the object it's self and not the class.
Usually they are defined in a Eigenclass.


3. When would you use DuckTypeing? How would you use it to improve your code?
if you were coding in C# or Java or Perl. Readability?. I did Perl in DuckTyping.
I wouldn't use it in Ruby.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You pretty much always use DuckTypeing, in that it's not necessary to declare types for objects in Ruby. It makes code more flexible and easier to maintain. The focus is on testing the capabilities of an object instead of its type.


4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval?
Class methods are methods that are called on a class, and instance methods are methods that are called on a instance of a class.
instance_eval defines class methods and class_eval defines instance methods.

5. What is the difference between a singleton class and a singleton method?

a singleton method is a method that is defined only for a single object,
and a singleton class is defined ON the object.
16 changes: 14 additions & 2 deletions week8/exercises/couch.rb
Original file line number Diff line number Diff line change
@@ -4,9 +4,21 @@ def initialize(pillows, cushions)
@cushions = cushions
end

[:pillows, :cushions, :dogs].each do |s|
# [:pillows, :cushions, :dogs].each do |s|
# define_method("how_many_#{s}") do
# instance_variable_get("@#{s}").count
# end
# end

[:pillows, :cushions ].each do |s|
define_method("how_many_#{s}") do
instance_variable_get("@#{s}").count
end
end
end

define_method("#{s.to_s.gsub('s', '')}_colors") do
instance_variable_get("@#{s}").each do | color |
puts color
end
end
end
1 change: 1 addition & 0 deletions week9/Songsoftheday
Submodule Songsoftheday added at e39e3c
5 changes: 5 additions & 0 deletions week9/comments_examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# how your doing something in a method
# something tied to sepcifics ..
# carefull about putting votile info in comments
# change code , don' t update the comments.
# that is bad ...
37 changes: 37 additions & 0 deletions week9/exceptional-ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# exception example
#class JonasError < Exception
# def message
# "its messed up "
# end
#end

#begin

#raise "AGGGG"
# raise JonasError.new

#puts 0/1

# f = File.open('hello.txt')
# f.close
# f.read
#rescue => e
##rescue => e
# puts e
# puts e.class
#rescue IOError => e
# puts "there was a io error"
#ensure
# puts "hello world"
#end
#
#
catch :yipes do

i = 0
while i<10
sleep (2) and throw :yipes if i == 5
puts i+=1
end
end

14 changes: 14 additions & 0 deletions week9/sinatra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'sinatra'
require 'sinatra/reloader'
require 'puma'

get '/' do
"<html>
<body>
<h1><fint color='pink'>HI<</font></h1>
<center>
</body>
</html>"
end


81 changes: 81 additions & 0 deletions week9/struce
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
jonashaskins@zadmins-MacBook-Pro-2~/RUBY_CLASS/RubyFall2013/week9$ irb
1.9.3p392 :001 > Dog = Struct.new(:name, :owner, :age)
=> Dog
1.9.3p392 :002 > d = Dog.new('Bradley', 'Jonas', '6')
=> #<struct Dog name="Bradley", owner="Jonas", age="6">
1.9.3p392 :003 > d.name
=> "Bradley"
1.9.3p392 :004 > d.age
=> "6"
1.9.3p392 :005 > d.owner
=> "Jonas"
1.9.3p392 :006 > d.name = "Rockey the Dog"
=> "Rockey the Dog"
1.9.3p392 :007 > d.name
=> "Rockey the Dog"
1.9.3p392 :008 > d.age = '100'
=> "100"
1.9.3p392 :009 > d.age
=> "100"
1.9.3p392 :010 >

1.9.3p392 :016 > d.each_pair do |i|
1.9.3p392 :017 > puts i
1.9.3p392 :018?> end
name
owner
age
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100">
1.9.3p392 :019 > d.each_pair{|k,v| puts k}
name
owner
age
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100">
1.9.3p392 :020 >




jonashaskins@zadmins-MacBook-Pro-2~/RUBY_CLASS/RubyFall2013/week9$ irb
1.9.3p392 :001 > Dog = Struct.new(:name, :owner, :age)
=> Dog
1.9.3p392 :002 > d = Dog.new('Bradley', 'Jonas', '6')
=> #<struct Dog name="Bradley", owner="Jonas", age="6">
1.9.3p392 :003 > d.name
=> "Bradley"
1.9.3p392 :004 > d.age
=> "6"
1.9.3p392 :005 > d.owner
=> "Jonas"
1.9.3p392 :006 > d.name = "Rockey the Dog"
=> "Rockey the Dog"
1.9.3p392 :007 > d.name
=> "Rockey the Dog"
1.9.3p392 :008 > d.age = '100'
=> "100"
1.9.3p392 :009 > d.age
=> "100"
1.9.3p392 :010 >
1.9.3p392 :011 >
1.9.3p392 :012 > d.map{|a|a}
=> ["Rockey the Dog", "Jonas", "100"]
1.9.3p392 :013 > d
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100">
1.9.3p392 :014 > d.select{|a|a == 7}
=> []
1.9.3p392 :015 > d.select{|a|a == 7}
=> []
1.9.3p392 :016 > d.each_pair do |i|
1.9.3p392 :017 > puts i
1.9.3p392 :018?> end
name
owner
age
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100">
1.9.3p392 :019 > d.each_pair{|k,v| puts k}
name
owner
age
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100">
1.9.3p392 :020 >

File renamed without changes.