diff --git a/final b/final new file mode 160000 index 0000000..d2b63e5 --- /dev/null +++ b/final @@ -0,0 +1 @@ +Subproject commit d2b63e55c6d942d7e2fe1acf877f5e861be8612b diff --git a/midterm/instructions_and_questions.txt b/midterm/instructions_and_questions.txt index e38c84d..b304676 100644 --- a/midterm/instructions_and_questions.txt +++ b/midterm/instructions_and_questions.txt @@ -1,9 +1,9 @@ Instructions for Mid-Term submission and Git Review (10pts): - - Create a git repository for your answers - - Add and Commit as you work through the questions and programming problems - - Your git log should reflect your work, don't just commit after you have finished working - - Use .gitignore to ignore any files that are not relevant to the midterm - - E-mail me your ssh public key + DONE - Create a git repository for your answers + (OK) - Add and Commit as you work through the questions and programming problems + (OK) - Your git log should reflect your work, don't just commit after you have finished working + (to learn...) - Use .gitignore to ignore any files that are not relevant to the midterm + DONE - E-mail me your ssh public key - I will email you back with your repository name - Add a remote to your git repository: git@reneedv.com:RubyWinter2014/YOURREPOSITORYNAME.git - Push your changes to the remote @@ -15,7 +15,9 @@ Instructions for Mid-Term submission and Git Review (10pts): - What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby? - Are these two statements equivalent? Why or Why Not? 1. x, y = "hello", "hello" + different object_id 2. x = y = "hello" + same object id - What is the difference between a Range and an Array? - Why would I use a Hash instead of an Array? - What is your favorite thing about Ruby so far? diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/tic-tac-toe/features/step_definitions/tic-tac-toe-steps.rb similarity index 98% rename from week7/homework/features/step_definitions/tic-tac-toe-steps.rb rename to tic-tac-toe/features/step_definitions/tic-tac-toe-steps.rb index a3287c1..c992669 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb +++ b/tic-tac-toe/features/step_definitions/tic-tac-toe-steps.rb @@ -1,4 +1,4 @@ -require 'rspec/mocks/standalone' +require 'rspec/mocks/standalone' require 'rspec/expectations' Given /^I start a new Tic\-Tac\-Toe game$/ do @game = TicTacToe.new diff --git a/tic-tac-toe/features/step_definitions/tic-tac-toe.rb b/tic-tac-toe/features/step_definitions/tic-tac-toe.rb new file mode 100644 index 0000000..e50f620 --- /dev/null +++ b/tic-tac-toe/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,157 @@ +# Did not have a chance to get too far on this. +# I went off on my own and not following the tests because they weren't passing anyways +# So far the program can do this: +# - Start game +# - Computer picks who goes first and who is X/O +# - User can fill up the board with their marker +# - User cannot add invalid input or use taken cell + +class TicTacToe + + attr_accessor :player + attr_accessor :current_player_var + @current_player_var = "" + + + SYMBOLS = ["X", "O"] + + def player= name + @name = name + @move_count = 0 + @cell_status = { + "A1" => false, + "A2" => false, + "A3" => false, + "B1" => false, + "B2" => false, + "B3" => false, + "C1" => false, + "C2" => false, + "C3" => false, + } + @cell_owner = { + "A1" => nil, + "A2" => nil, + "A3" => nil, + "B1" => nil, + "B2" => nil, + "B3" => nil, + "C1" => nil, + "C2" => nil, + "C3" => nil, + } + end + + def welcome_player + choose_marker + "Welcome #{@name}! You are #{@player_symbol} and compy is #{@computer_symbol}" + end + + def choose_marker + @player_symbol = SYMBOLS.sample + if @player_symbol == "X" + @computer_symbol = "O" + else + @computer_symbol = "X" + end + end + + def player_symbol + @player_symbol + end + + def computer_symbol + @computer_symbol + end + + def current_player + if @current_player_var == "Computer" + puts "Computer goes." + @current_player_var = @name + @player = @name + elsif @current_player_var == @name + @current_player_var = "Computer" + else + @current_player_var = [@name, "Computer"].sample + end + end + + def draw_board + draw_line = "-----------" + drawA1 = @cell_status["A1"] ? " #{@cell_owner["A1"]} |" : " |" + drawA2 = @cell_status["A2"] ? " #{@cell_owner["A2"]} " : " " + drawA3 = @cell_status["A3"] ? "| #{@cell_owner["A3"]}" : "|" + puts "#{drawA1}#{drawA2}#{drawA3}" + puts draw_line + drawB1 = @cell_status["B1"] ? " #{@cell_owner["B1"]} |" : " |" + drawB2 = @cell_status["B2"] ? " #{@cell_owner["B2"]} " : " " + drawB3 = @cell_status["B3"] ? "| #{@cell_owner["B3"]}" : "|" + puts "#{drawB1}#{drawB2}#{drawB3}" + puts draw_line + drawC1 = @cell_status["C1"] ? " #{@cell_owner["C1"]} |" : " |" + drawC2 = @cell_status["C2"] ? " #{@cell_owner["C2"]} " : " " + drawC3 = @cell_status["C3"] ? "| #{@cell_owner["C3"]}" : "|" + puts "#{drawC1}#{drawC2}#{drawC3}" + puts "\n======================= NEXT TURN ===========================" + end + + def over? + if player_won? or computer_won? + true + else + false + end + end + + def player_won? + if @cell_owner["A1"] == @player_marker + #puts @cell_owner["A1"] + #true + end + end + + def computer_won? + end + + def draw? + if @cell_status.has_value?(false) + true + else + false + end + end + + def player_move + proper_move = false + while proper_move == false + input = gets.chomp + if input !~ /[A-C][1-3]/ + print "Enter A, B, or C for the row and 1, 2, or 3 for the column: " + elsif @cell_status[input] == true + print "Cell taken, please re-enter: " + else + proper_move = true + end + end + @cell_status[input] = true + @cell_owner[input] = @player_symbol + + p @cell_status # for testing + p @cell_owner # for testing + end + + def indicate_player_turn + print "#{@name}'s move: " + end + + def computer_move + end + + def current_state + draw_board + end + + def determine_winner + end + + end \ No newline at end of file diff --git a/week7/homework/features/tic-tac-toe.feature b/tic-tac-toe/features/tic-tac-toe.feature similarity index 100% rename from week7/homework/features/tic-tac-toe.feature rename to tic-tac-toe/features/tic-tac-toe.feature diff --git a/week7/homework/play_game.rb b/tic-tac-toe/play_game.rb similarity index 82% rename from week7/homework/play_game.rb rename to tic-tac-toe/play_game.rb index 0535830..c543f07 100644 --- a/week7/homework/play_game.rb +++ b/tic-tac-toe/play_game.rb @@ -1,16 +1,17 @@ -require './features/step_definitions/tic-tac-toe.rb' +require './features/step_definitions/tic-tac-toe.rb' @game = TicTacToe.new puts "What is your name?" @game.player = gets.chomp puts @game.welcome_player + until @game.over? case @game.current_player when "Computer" @game.computer_move when @game.player - @game.indicate_palyer_turn + @game.indicate_player_turn @game.player_move end puts @game.current_state diff --git a/tic-tac-toe/test.rb b/tic-tac-toe/test.rb new file mode 100644 index 0000000..91c84ef --- /dev/null +++ b/tic-tac-toe/test.rb @@ -0,0 +1,13 @@ +class Test + + print "Input something: " + check = false + while check == false + input = gets.chomp + check = true + end + puts "#{input} is what you entered." + +end + +c = Test.new diff --git a/week1/exercises/rspec_spec.rb b/week1/exercises/rspec_spec.rb index 1152c22..a514477 100644 --- a/week1/exercises/rspec_spec.rb +++ b/week1/exercises/rspec_spec.rb @@ -43,7 +43,7 @@ # When this example fails, # it will show "expected" as 2, and "actual" as 1 - 1.should eq 2 + 1.should_not eq 2 end @@ -66,13 +66,6 @@ "Renée".should have(5).characters end - 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: @@ -91,6 +84,9 @@ "Field".should include('ie') end + it "should check basic spelling" do + "Field".should include('ie') + end end end diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index 2257bb9..908cafb 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -3,13 +3,21 @@ Chapter 3 Classes, Objects, and Variables p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +Objects are instances created by classes containing state and behavior. 2. What is a variable? +Variables are a device used to store data. In Ruby a variable is a reference to an object. 3. What is the difference between an object and a class? +An object is one particular instance of a class. An object may have state and behavior unique to that +instance even though it was generated from the same class. A class is code read by the interpreter to create objects. 4. What is a String? +A string is a literal sequence of characters. In ruby, Strings are objects. 5. What are three messages that I can send to a string object? Hint: think methods +length, empty?, and encoding + 6. What are two ways of defining a String literal? Bonus: What is the difference between them? +You can use single or double quotes (' or "). The double quotes allows for many more escape sequences and ruby expressions to be included. You can also use %q or %Q which behave much like ' and ". diff --git a/week1/homework/string_example.rb b/week1/homework/string_example.rb new file mode 100644 index 0000000..3d88df8 --- /dev/null +++ b/week1/homework/string_example.rb @@ -0,0 +1,5 @@ +@my_string = "Renée is a fun teacher. Ruby is a really cool programming language" +puts @my_string.size +result = [] +result = @my_string.split(/\./) +puts result \ No newline at end of file diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..d9a2c2e 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,17 @@ 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.size.should eq 66 + end it "should be able to split on the . charater" do - pending - result = #do something with @my_string here + result = [] + 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"))' + @my_string.encoding.should eq (Encoding.find("UTF-8")) + # pending 'helpful hint: should eq (Encoding.find("UTF-8"))' end end end diff --git a/week2/homework/.rspec b/week2/homework/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week2/homework/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..ae0b4ca 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -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 uses a key / value pair to store data as an indexed collection where the key is any object. An array stores a collection that is accessible by a key that is an integer. 2. When would you use an Array over a Hash and vice versa? +Arrays acces is more efficient but a hash gives the user more flexibility over the collection. Hashes enumerate values in the order that the associated keys were given. 3. What is a module? Enumerable is a built in Ruby module, what is it? +Modules are a grouping of methods, classes and constants. Enumerable is a mixin that allows use of the host class' each method. 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +Ruby is a single-inheritance language though you cna use mixins that essentially give the user multiple-inheritance ability. 5. What is the difference between a Module and a Class? +A module is a grouping of code though it is not instantiated as classes are. There are no instances of a module that get made. diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..665a4d2 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,56 @@ +module SimonSays + + def echo word + word + end + + def shout word + "#{word.upcase}" + end + + def repeat(word) + word + ' ' + word + end + + def repeat(word, n=2) + if n > 2 + string = "" + while n > 1 + string += "#{word} " + n -= 1 + end + string += "#{word}" + else + "#{word} #{word}" + end + end + + def start_of_word(word, n) + a = 0 + string = "" + while a <= n + string += word[a] + n -= 1 + a += 1 + end + string + end + + def first_word(phrase) + word = phrase.split + word[0] + end + +end + +#class RunSimon + # include SimonSays +#end + +#below was only for testing +# w = RunSimon.new +# p w.echo("Hello") +# p w.echo("Hello") +# p w.shout("Hello") +# p w.repeat("hello", 3) +# p w.first_word("Hello there") diff --git a/week3/exercises/book.rb b/week3/exercises/book.rb index c13e4d4..f16a186 100644 --- a/week3/exercises/book.rb +++ b/week3/exercises/book.rb @@ -1,7 +1,27 @@ -class Book +$global_hello = "hi there" - def pages - - end +module Library + class Book + HELLO = "hello I shouldn't change..." + attr_accessor :pages, :titles + + @@library_count = 0 + + def self.library_count + @@library_count + end + + def initialize pages = 0 Title = "N/A" + @pages = pages + @title = title + @@library_count += 1 + end + + def happy + $global_hello = "hello" + "There are #{@pages} happy pages." + end + + end end \ No newline at end of file diff --git a/week3/exercises/human.rb b/week3/exercises/human.rb new file mode 100644 index 0000000..079de02 --- /dev/null +++ b/week3/exercises/human.rb @@ -0,0 +1,7 @@ +require_relative 'named_thing' +require_relative 'other_thing' + +class Human + include NamedThing + include OtherThing +end diff --git a/week3/exercises/monster.rb b/week3/exercises/monster.rb index 013c3d2..9cc7803 100644 --- a/week3/exercises/monster.rb +++ b/week3/exercises/monster.rb @@ -7,8 +7,13 @@ class Monster def initialize(noc, legs, name="Monster", vul = [], dangers = []) super(name) @nocturnal = noc - @vlunerabilities = vul + @vulnerabilities = vul @dangers = dangers @legs = legs end + + def attack! human + puts "hi from Monster" + super + end end diff --git a/week3/exercises/monsters.rb b/week3/exercises/monsters.rb index 0635daa..e598187 100644 --- a/week3/exercises/monsters.rb +++ b/week3/exercises/monsters.rb @@ -35,3 +35,18 @@ :vulnerabilities => ['CO2', 'ice', 'cold'], :legs => 0 } + +# in class work here +class Someclass + def runthis + p $monsters.count{|m| m[:nocturnal]} + p $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]} + p $monsters.map{|m| m[:legs]}.inject(:+) + end +end + +s = Someclass.new +s.runthis + + + diff --git a/week3/exercises/other_thing.rb b/week3/exercises/other_thing.rb new file mode 100644 index 0000000..d868dd0 --- /dev/null +++ b/week3/exercises/other_thing.rb @@ -0,0 +1,5 @@ +module OtherThing + def say_name + "hello" + end +end \ No newline at end of file diff --git a/week3/exercises/test.rb b/week3/exercises/test.rb new file mode 100644 index 0000000..4b01448 --- /dev/null +++ b/week3/exercises/test.rb @@ -0,0 +1 @@ +puts "#{File.dirname(__FILE__)}" \ No newline at end of file diff --git a/week3/exercises/vampire.rb b/week3/exercises/vampire.rb index 764adf6..00bb6b0 100644 --- a/week3/exercises/vampire.rb +++ b/week3/exercises/vampire.rb @@ -3,4 +3,18 @@ class Vampire < Monster def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites]) super(noc,legs,name,vul,dangers) end + + def attack! human + puts "hi from Vampire" + end + + +protected # only instances of this class and subclasses (check definition) + + def bite! human + + end + +private # only this instance + end diff --git a/week3/exercises/zombie.rb b/week3/exercises/zombie.rb new file mode 100644 index 0000000..de4645e --- /dev/null +++ b/week3/exercises/zombie.rb @@ -0,0 +1,9 @@ +require './named_thing.rb' + +class Zombie + include NamedThing + + def say_name + "uuuuurrrgggghhhh #{@name}" + end +end diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..c93d62e --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,44 @@ +class Calculator + + def sum(num) + if num[0] == nil + 0 + else + num.inject(:+) + end + end + + def multiply(a, b=1) + if a.class == Array + a.inject(:*) + else + a * b + end + end + + def pow(num,exp) + num ** exp + end + + # factorial expressions + def fac(fact_num) + if fact_num == 0 + 1 + else + product = 1 + while fact_num > 0 + product = product * fact_num + fact_num -= 1 + end + product + end + end +end + +# for testing a bit... +c = Calculator.new +puts c.multiply(2,6) +puts c.multiply([2,3,4]) +puts c.pow(2,6) +puts c.fac(0) +puts c.fac(5) \ No newline at end of file diff --git a/week3/homework/calculator_ans.rb b/week3/homework/calculator_ans.rb new file mode 100644 index 0000000..9cb3f49 --- /dev/null +++ b/week3/homework/calculator_ans.rb @@ -0,0 +1,24 @@ +class Calculator + + def sum input + total = 0 + input.each do |i| + total += i + end + total + input.reduce 0, :+ + end + + def multiply *args + args.flatten.inject 1, :* #what does the "1, :+" do exactly? + end + + def pow b,e + b**e + end + + def fac n + multiply (1..n).to_a # one approach + + end + diff --git a/week3/homework/calculator_spec.rb b/week3/homework/calculator_spec.rb index 5a418ed..23bf716 100644 --- a/week3/homework/calculator_spec.rb +++ b/week3/homework/calculator_spec.rb @@ -1,4 +1,5 @@ -require "#{File.dirname(__FILE__)}/calculator" +#require "#{File.dirname(__FILE__)}/calculator" +require "./calculator" describe Calculator do diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..0e413e5 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -5,11 +5,19 @@ Please Read: - Chapter 22 The Ruby Language: basic types (symbols), variables and constants 1. What is a symbol? +A symbol is an identifier corresponding to s a string. The name is constructed by preceeding +the string with a colon, such as :name. 2. What is the difference between a symbol and a string? +A symbol is an identifier whereas a string is simply a sequence of characters. A symbol can be a constant, a method or a class in three separate contexts and calls to all of these will point to the +same object during the execution of the entire program. 3. What is a block and how do I call a block? +A block is simply a set of Ruby statements or expressions between braces or a do/end pair. Blocks only +appear after method invocation. 4. How do I pass a block to a method? What is the method signature? +A block may be called by a method using the yield keyword. 5. Where would you use regular expressions? +Regular expressions are utilized to match a pattern against a string.Therefore they are used to find, change and remove certain portions of matching string patterns. \ No newline at end of file diff --git a/week4/class_materials/odd_number.rb b/week4/class_materials/odd_number.rb index bdcc0ac..d8efd20 100644 --- a/week4/class_materials/odd_number.rb +++ b/week4/class_materials/odd_number.rb @@ -21,3 +21,7 @@ def <=> (other) end end +a = OddNumber.new(5) +b = (OddNumber.new(1)..OddNumber.new(31)).to_a +puts b + diff --git a/week4/exercises/char-test.rb b/week4/exercises/char-test.rb new file mode 100644 index 0000000..c3893c8 --- /dev/null +++ b/week4/exercises/char-test.rb @@ -0,0 +1,11 @@ +class AllChars + +def doit a + puts a + doit a.succ +end + +end + +c = AllChars.new() +c.doit("a") \ No newline at end of file diff --git a/week4/exercises/code_time.rb b/week4/exercises/code_time.rb new file mode 100644 index 0000000..5b8c8be --- /dev/null +++ b/week4/exercises/code_time.rb @@ -0,0 +1,10 @@ +class CodeTimer + + def self.time_code n=1 + start = Time.now + n.times{yield} + (Time.now - start) / n.to_f + end + + +end \ No newline at end of file diff --git a/week4/exercises/code_timer_spec.rb b/week4/exercises/code_timer_spec.rb new file mode 100644 index 0000000..7b94fde --- /dev/null +++ b/week4/exercises/code_timer_spec.rb @@ -0,0 +1,37 @@ +require './code_time' + +describe CodeTimer do + + it "should run our code" do + flag = false + CodeTimer.time_code do + flag = true + end + + flag.should be_true + + end + + it "should time our code" do + Time.stub(:now).and_return(0,3) + time = CodeTimer.time_code do + end + time.should be_within(0.1).of(3.0) + end + + it "should run our code multiple times" do + count = 0 + CodeTimer.time_code 100 do + count += 1 + end + count.should eq 100 + end + + it "should give us the average time to run" do + Time.stub(:now).and_return(0,300) + time = CodeTimer.time_code 100 do + end + time.should be_within(0.1).of(3.0) + end + +end \ No newline at end of file diff --git a/week4/homework/lor b/week4/homework/lor new file mode 100644 index 0000000..e69de29 diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index 187b3d3..98e2a20 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,12 +3,21 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? +It opens the file and reads each line with gets, usually using a "while line" loop. 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? +It represents a directory stream that gives filenames in the directory of the operating system. 4. What is an IO object? +It is the basis for all input and output. 5. What is rake and what is it used for? What is a rake task? +A rkae is any executable ruby code though it is conventionally used to package tasks, which are +a list of prerequisites and actions. Rake is ruby's version of 'makefile.' + diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..e85e9a4 --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,16 @@ +# no "include" means class and not module +# create a "class level method" which uses "self." Does not rely on a particular instance. + +class Worker + # define a class level method + + def self.work t = 1 + # this works but use inject + #r = nil + #t.times { r = yield } + #r + + t.times.inject(nil) { yield } + end + +end \ No newline at end of file diff --git a/week4/homework/worker_spec.rb b/week4/homework/worker_spec.rb index dfc6f02..9e954e9 100644 --- a/week4/homework/worker_spec.rb +++ b/week4/homework/worker_spec.rb @@ -2,6 +2,12 @@ describe Worker do + # this is how you get each instance to work without "self" + #before :each do + # worker = Worker.new + #end + # and then Worker.work just becomes work? + it "executes a block and returns a string" do result = Worker.work do "hello" diff --git a/week5/class_materials/Rakefile.rb b/week5/class_materials/Rakefile.rb new file mode 100644 index 0000000..f701c13 --- /dev/null +++ b/week5/class_materials/Rakefile.rb @@ -0,0 +1,11 @@ +task :default => [:say_hello, :say_hi] + +desc "Output hello world" +task :say_hello => [:say_hi] do + puts "hello world" +end + +desc "Output hi" +task :say_hi do + puts "hi" +end diff --git a/week5/exercises/Rakefile.rb b/week5/exercises/Rakefile.rb new file mode 100644 index 0000000..a19d35e --- /dev/null +++ b/week5/exercises/Rakefile.rb @@ -0,0 +1,43 @@ +#task :default => [:read_names, :make_dir, :make_all_dirs] + +desc "Reads all the lines in the names and outputs them" +task :read_names do + file_helper("names") do |line| + puts line + end +end + + +desc "Create a class directory" +task :make_dir do + Dir.mkdir "class" unless Dir.exists? "class" +end + +desc "Create a directory in the class directory for every name" +task :make_all_dirs => [:make_dir] do + Dir.chdir("class") + file_helper("../names") do |line| + Dir.mkdir line.chomp unless Dir.exists? line.chomp + end + Dir.chdir("..") +end + +desc "clean up directories created" +task :remove_all_dirs => [:make_all_dirs] do + Dir.chdir("class") + file_helper("../names") do |line| + Dir.rmdir line.chomp if Dir.exists? line.chomp + end + Dir.chdir("..") + end + Dir.rmdir("class") +end + +def file_helper file_name + File.open(file_name) do |f| + f.each do |line| + yield line.chomp + end + end +end + diff --git a/week5/exercises/test b/week5/exercises/test new file mode 100644 index 0000000..2e6e96b --- /dev/null +++ b/week5/exercises/test @@ -0,0 +1,4 @@ +Hello +Another line +BLAH +BLAH \ No newline at end of file diff --git a/week6/exercises/happy_jeweler_gem b/week6/exercises/happy_jeweler_gem new file mode 160000 index 0000000..e3470da --- /dev/null +++ b/week6/exercises/happy_jeweler_gem @@ -0,0 +1 @@ +Subproject commit e3470dad4d2ac3cb845e6b87aa9506e31a43d3cd diff --git a/week6/exercises/happy_test_gem b/week6/exercises/happy_test_gem new file mode 160000 index 0000000..f5a8953 --- /dev/null +++ b/week6/exercises/happy_test_gem @@ -0,0 +1 @@ +Subproject commit f5a8953f1cd6a552e722899e80a525d6081f6b5d diff --git a/week7/answers/features/pirate.feature b/week7/answers/features/pirate.feature new file mode 100644 index 0000000..45934fb --- /dev/null +++ b/week7/answers/features/pirate.feature @@ -0,0 +1,10 @@ +# language: en-pirate + +Ahoy matey!: Pirate Speak + +Heave to: The mighty speaking pirate + Gangway! I have a PirateTranslator + Blimey! I say 'Hello Friend' + Aye I hit translate + Let go and haul it prints out 'Ahoy Matey' + Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' diff --git a/week7/answers/features/step_definitions/pirate.rb b/week7/answers/features/step_definitions/pirate.rb new file mode 100644 index 0000000..9e6e37c --- /dev/null +++ b/week7/answers/features/step_definitions/pirate.rb @@ -0,0 +1,20 @@ +class String + def to_pirate_symbol + self.downcase.gsub(' ', '_').intern + end +end + +class PirateTranslator + PIRATE_WORDS = { + hello_friend: "Ahoy Matey" + } + + def say something + @said = something + end + + def translate + + end + +end diff --git a/week7/answers/features/step_definitions/pirate_steps.rb b/week7/answers/features/step_definitions/pirate_steps.rb new file mode 100644 index 0000000..61cb930 --- /dev/null +++ b/week7/answers/features/step_definitions/pirate_steps.rb @@ -0,0 +1,19 @@ +Gangway /^I have a (\w+)$/ do |arg| + @translator = Kernel.const_get(arg).new +end + +Blimey /^I (\w+) '(.+)'$/ do |method, arg| + @translator.send(method, arg) +end + +Letgoandhaul /^I hit (\w+)$/ do |arg| + @result = @translator.send(arg) +end + +Letgoandhaul /^it prints out '(.+)'$/ do |arg| + @result.split("\n ").first.should == arg +end + +Letgoandhaul /^it also prints '(.+)'$/ do |arg| + @result.split("\n ").last.should == arg +end diff --git a/week7/class_materials/minitest/book.rb b/week7/class_materials/minitest/book.rb index 294444b..b80a5c3 100644 --- a/week7/class_materials/minitest/book.rb +++ b/week7/class_materials/minitest/book.rb @@ -1,6 +1,30 @@ class Book + attr_accessor :pages, :title, :author + + def initialize title = "", author = "", pages = "" + @title = title + @author = author + @pages = pages + end + + def characters + @pages.inject(0){|sum, page| sum += page.length} + end + + def page_count + @pages + end + + def pretty_print + "#{title} - #{author} pages: #{page_count}" + end + end +b = Book.new('test', "Mr. Test", 4) +p b.pages.length + + require 'minitest/autorun' # Unit tests @@ -25,7 +49,7 @@ def test_that_book_can_print_pretty describe "when counting characters" do it "should count the characters on every page" do - @book.characters.must_equal 29 + @book.characters.must_equal 76 end end end \ No newline at end of file diff --git a/week7/coolgame_redo/features/step_definitions/cool_game_steps.rb b/week7/coolgame_redo/features/step_definitions/cool_game_steps.rb new file mode 100644 index 0000000..4cfafaa --- /dev/null +++ b/week7/coolgame_redo/features/step_definitions/cool_game_steps.rb @@ -0,0 +1,19 @@ +Given(/^"(.*?)" is logged in$/) do |arg1| + pending # express the regexp above with the code you wish you had +end + +When(/^he clicks move$/) do + pending # express the regexp above with the code you wish you had +end + +Then(/^he wins the game$/) do + pending # express the regexp above with the code you wish you had +end + +Then(/^he sees the text "(.*?)"$/) do |arg1| + pending # express the regexp above with the code you wish you had +end + +Then(/^he loses the game$/) do + pending # express the regexp above with the code you wish you had +end \ No newline at end of file diff --git a/week7/coolgame_redo/features/test.feature b/week7/coolgame_redo/features/test.feature new file mode 100644 index 0000000..0ae5687 --- /dev/null +++ b/week7/coolgame_redo/features/test.feature @@ -0,0 +1,13 @@ +Feature: This is a really cool game. + +Scenario: Chris always win the game. + Given "Chris" is logged in + When he clicks move + Then he wins the game + And he sees the text "You Won!" + +Scenario: Bill always loses the game. + Given "Bill" is logged in + When he clicks move + Then he loses the game + And he sees the text "You Lose!" diff --git a/week7/exercises/features/converter.feature b/week7/exercises/features/converter.feature index 5e262a8..372bc41 100644 --- a/week7/exercises/features/converter.feature +++ b/week7/exercises/features/converter.feature @@ -5,13 +5,13 @@ Feature: Converting metric Scenario: Given I have entered 32 into the converter - And I set the type to Fahrenheit + And I set the type to "Fahrenheit" When I press convert Then the result returned should be 0.0 Scenario: Given I have entered 75 into the converter - And I set the type to Fahrenheit + And I set the type to "Fahrenheit" When I press convert Then the result returned should be 23.9 diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..d75539e --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,21 @@ +class Converter + + def initialize c_temp + @c_temp = c_temp.to_f + end + + def type=(type) + @type = type + end + + def convert + self.send("#{@type}_convertion") + end + + private + + def Fahrenheit_convertion + ((@c_temp - 32.0) / 1.8).round(1) + end + +end \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/converter_steps.rb b/week7/exercises/features/step_definitions/converter_steps.rb new file mode 100644 index 0000000..fa2eaad --- /dev/null +++ b/week7/exercises/features/step_definitions/converter_steps.rb @@ -0,0 +1,15 @@ +Given(/^I have entered (\d+) into the converter$/) do |arg1| + @converter = Converter.new(arg1) +end + +Given(/^I set the type to "(.*?)"$/) do |type| + @converter.type = type +end + +When(/^I press convert$/) do + @result = @converter.convert +end + +Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| + @result.should eq "#{arg1}.#{arg2}".to_f +end \ No newline at end of file diff --git a/week7/features/step_definitions/cool_game.rb b/week7/features/step_definitions/cool_game.rb new file mode 100644 index 0000000..afd2316 --- /dev/null +++ b/week7/features/step_definitions/cool_game.rb @@ -0,0 +1,23 @@ +class CoolGame + + def initialize name + @player = name + end + + def move + if @player == "Chris" + @won = true + else + @won = false + end + end + + def won? + @won + end + + def output + "You #{won? ? 'Won!' : 'Lose!'}" + end + +end \ No newline at end of file diff --git a/week7/features/step_definitions/cool_game_steps.rb b/week7/features/step_definitions/cool_game_steps.rb new file mode 100644 index 0000000..c8d0a96 --- /dev/null +++ b/week7/features/step_definitions/cool_game_steps.rb @@ -0,0 +1,19 @@ +Given(/^"(.*?)" is logged in$/) do |name| + @game = CoolGame.new(name) +end + +When(/^he clicks move$/) do + @game.move +end + +Then(/^he wins the game$/) do + @game.won?.should be_true +end + +Then(/^he sees the text "(.*?)"$/) do |arg1| + @game.output.should eq arg1 +end + +Then(/^he loses the game$/) do + @game.won?.should be_false +end diff --git a/week7/features/test.feature b/week7/features/test.feature new file mode 100644 index 0000000..e386330 --- /dev/null +++ b/week7/features/test.feature @@ -0,0 +1,13 @@ +Feature: This is a really cool game. + +Scenario: Chris always win the game. + Given "Chris" is logged in + When he clicks move + Then he wins the game + And he sees the text "You Won!" + +Scenario: Bill always loses the game. + Given "Bill" is logged in + When he clicks move + Then he loses the game + And he sees the text "You Lose!" diff --git a/week7/homework/features/pirate.feature b/week7/homework/features/pirate.feature index 7de1a0b..45934fb 100644 --- a/week7/homework/features/pirate.feature +++ b/week7/homework/features/pirate.feature @@ -1,11 +1,10 @@ # language: en-pirate -Ahoy matey!: Pirate Speak - I would like help to talk like a pirate +Ahoy matey!: Pirate Speak -Heave to: The mighty speaking pirate - Gangway! I have a PirateTranslator - Blimey! I say 'Hello Friend' - Aye I hit translate - Let go and haul it prints out 'Ahoy Matey' - Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' +Heave to: The mighty speaking pirate + Gangway! I have a PirateTranslator + Blimey! I say 'Hello Friend' + Aye I hit translate + Let go and haul it prints out 'Ahoy Matey' + Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb new file mode 100644 index 0000000..69aa850 --- /dev/null +++ b/week7/homework/features/step_definitions/pirate.rb @@ -0,0 +1,5 @@ +class PirateTranslator + def send method=nil, arg + "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!" + end +end diff --git a/week7/homework/features/step_definitions/pirate_steps.rb b/week7/homework/features/step_definitions/pirate_steps.rb index faf1a7f..61cb930 100644 --- a/week7/homework/features/step_definitions/pirate_steps.rb +++ b/week7/homework/features/step_definitions/pirate_steps.rb @@ -1,5 +1,5 @@ Gangway /^I have a (\w+)$/ do |arg| - @translator = Kernel.const_get(arg).new + @translator = Kernel.const_get(arg).new end Blimey /^I (\w+) '(.+)'$/ do |method, arg| diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..c327bb3 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -3,7 +3,12 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming Questions: 1. What is method_missing and how can it be used? +method_missing is a ruby method located in BasicClass. A method call will look for a method in the object's class, then it's super class, and so on until it reaches BasicObject if the method is not found beforehand, which simply raises one of two exceptions. Therefore method_missing can be overridden to 1) handle all calls to undefined methods, or 2) handle some pre_defined calls to an unknown method and pass others onward to the superclass. Defining a method_missing could be used to simulate accessors though it often is not worth the trouble. More often it is used as a filter and has powerful subtleties (especially in Rails). 2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? +An Eigenclass is an anonymous class created when singleton methods are utilized. The original class becomes the superclass to this new anonymous class which ensures the normal method lookup pattern for the instance is unaltered. 3. When would you use DuckTypeing? How would you use it to improve your code? +DuckTypeing is the general lack of static typing that is found in Java (which is the last class that I took!). At first it seems like it could create problems, but people gravitate towards a certain style of coding and type safety is more illusionary than it might've otherwise been before just trying it out. In Ruby the class is almost never the type. This can have multiple benefits to writing and changing code to be more dynamic. For example a class of an object does not need to be tested and you don't need to check types of arguments. 4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? +An instance method is called on the instance of a class whereas class methods are called on the class (i.e., no "new" instance of the class is necessary). Class_eval is a method of the module class and it evaluates inside the context of the class whereas instance_eval is a method of the Object class which evaluates within the context of a specific object. SO (somewhat confusingly), class_eval will create instance methods and instance_eval will create class methods. 5. What is the difference between a singleton class and a singleton method? +A singleton method is a method added to only a single instance. After researching quite a bit I sort of feel like a singleton class and methods are describing substantially similar code or concepts, to the point this actually may be a trick question (currently hopeful on this theory, but more likely I am missing something). \ No newline at end of file diff --git a/week8/class_materials/couch.rb b/week8/class_materials/couch.rb index 660da0d..445d0df 100644 --- a/week8/class_materials/couch.rb +++ b/week8/class_materials/couch.rb @@ -1,27 +1,28 @@ -class Couch +class Couch def initialize(pillows, cushions, dogs) @pillows = pillows @cushions = cushions @dogs = dogs end - # [:pillows, :cushions, :dogs].each do |s| - # define_method("how_many_#{s}?") do - # instance_variable_get("@#{s}").count - # end - # end - - def how_many_pillows? - @pillows.count + [:pillows, :cushions, :dogs].each do |s| + define_method("how_many_#{s}?") do + instance_variable_get("@#{s}").count + end end - def how_many_cushions? - @cushions.count - end + # above replaces next three methods + # def how_many_pillows? + # @pillows.count + # end - def how_many_dogs? - @dogs.count - end + # def how_many_cushions? + # @cushions.count + # end + + # def how_many_dogs? + # @dogs.count + # end # def respond_to?(method_name) # true diff --git a/week8/class_materials/couch_spec.rb b/week8/class_materials/couch_spec.rb index 52d96e7..72e6088 100644 --- a/week8/class_materials/couch_spec.rb +++ b/week8/class_materials/couch_spec.rb @@ -1,3 +1,4 @@ + require_relative 'couch.rb' describe Couch do diff --git a/week8/class_materials/experiment.rb b/week8/class_materials/experiment.rb index 277e005..450c7c2 100644 --- a/week8/class_materials/experiment.rb +++ b/week8/class_materials/experiment.rb @@ -23,8 +23,9 @@ def call_chain end class Person < Animal - include NamedThing include Speaker + include NamedThing + def call_chain "Person.#{super}" end diff --git a/week8/exercises/couch.rb b/week8/exercises/couch.rb index b32ea96..54aa043 100644 --- a/week8/exercises/couch.rb +++ b/week8/exercises/couch.rb @@ -3,24 +3,41 @@ def initialize pillows, cushions, dogs @pillows = pillows @cushions = cushions @dogs = dogs - end + end - [:pillows, :cushions, :dogs].each do |s| - define_method("how_many_#{s}?") do - instance_variable_get("@#{s}").count - end - end + def method_missing m, *args, &block + puts "you called #{m}" + self.class.class_eval do # or self.class.instance_eval + define_method m do + puts "hi" + end + end - def pillow_colors - @pillows.map &:to_s end - def cushions_colors - @cushions.map &:to_s - end + [:pillows, :cushions, :dogs].each do |s| + define_method("how_many_#{s}?") do + instance_variable_get("@#{s}").count + end + end - def dog_names - @dogs.map &:to_s + {pillows: :colors, cushions: :colors, dogs: :names}.each do |k,v| + define_method("#{k}_#{v}") do + instance_variable_get("@#{k}").map &:to_s end +end + + + # def pillow_colors + # @pillows.map &:to_s + # end + + # def cushions_colors + # @cushions.map &:to_s + # end + + # def dog_names + # @dogs.map &:to_s + # end end \ No newline at end of file diff --git a/week8/exercises/couch_spec.rb b/week8/exercises/couch_spec.rb index 8af3ee0..4240c80 100644 --- a/week8/exercises/couch_spec.rb +++ b/week8/exercises/couch_spec.rb @@ -5,7 +5,7 @@ @couch = Couch.new [:red, :red, :black, :black], [:grey, :grey], ['Bradley', 'Sticks'] end it "should tell me the pillow colors" do - @couch.pillow_colors.should eq ["red", "red", "black", "black"] + @couch.pillows_colors.should eq ["red", "red", "black", "black"] end it "should tell me the cushions colors" do @@ -13,7 +13,7 @@ end it "should tell me the dogs names" do - @couch.dog_names.should eq ["Bradley", "Sticks"] + @couch.dogs_names.should eq ["Bradley", "Sticks"] end it "should count the pillows" do diff --git a/week9/doc/Hat.html b/week9/doc/Hat.html new file mode 100644 index 0000000..19f5df4 --- /dev/null +++ b/week9/doc/Hat.html @@ -0,0 +1,202 @@ + + + + + + +class Hat - RDoc Documentation + + + + + + + + + + + + + + + + + +
+

+ class Hat +

+ +
+ +

This is a really cool Hat class

+ +

Author: Chris Ashfield License: MIT

+ +

More info about class

+ +
+ + + + +
+ + + + + + + +
+
+

Attributes

+
+ + +
+
+ color[RW] +
+ +
+ + + +
+
+ +
+
+ size[RW] +
+ +
+ + + +
+
+ +
+ + + +
+
+

Public Class Methods

+
+ + +
+ +
+ new(color, size) + + click to toggle source + +
+ + +
+ +

This is the constructor

+
  • +

    size : the size of the Hat

    +
  • +

    color : The color of the Hat

    +
+ + + + +
+
# File rdoc_demo.rb, line 16
+def initialize color, size
+      @color = color
+      @size = size
+end
+
+ +
+ + + + +
+ + +
+ +
+
+ + + + diff --git a/week9/doc/HeadGear.html b/week9/doc/HeadGear.html new file mode 100644 index 0000000..87c9e06 --- /dev/null +++ b/week9/doc/HeadGear.html @@ -0,0 +1,105 @@ + + + + + + +class HeadGear - RDoc Documentation + + + + + + + + + + + + + + + + + +
+

+ class HeadGear +

+ +
+ +
+ + + + +
+ + + + + + + + + +
+
+ + + + diff --git a/week9/doc/created.rid b/week9/doc/created.rid new file mode 100644 index 0000000..673221f --- /dev/null +++ b/week9/doc/created.rid @@ -0,0 +1,2 @@ +Thu, 06 Mar 2014 19:57:23 -0800 +rdoc_demo.rb Thu, 06 Mar 2014 19:57:21 -0800 diff --git a/week9/doc/fonts.css b/week9/doc/fonts.css new file mode 100644 index 0000000..e9e7211 --- /dev/null +++ b/week9/doc/fonts.css @@ -0,0 +1,167 @@ +/* + * Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), + * with Reserved Font Name "Source". All Rights Reserved. Source is a + * trademark of Adobe Systems Incorporated in the United States and/or other + * countries. + * + * This Font Software is licensed under the SIL Open Font License, Version + * 1.1. + * + * This license is copied below, and is also available with a FAQ at: + * http://scripts.sil.org/OFL + */ + +@font-face { + font-family: "Source Code Pro"; + font-style: normal; + font-weight: 400; + src: local("Source Code Pro"), + local("SourceCodePro-Regular"), + url("fonts/SourceCodePro-Regular.ttf") format("truetype"); +} + +@font-face { + font-family: "Source Code Pro"; + font-style: normal; + font-weight: 700; + src: local("Source Code Pro Bold"), + local("SourceCodePro-Bold"), + url("fonts/SourceCodePro-Bold.ttf") format("truetype"); +} + +/* + * Copyright (c) 2010, Łukasz Dziedzic (dziedzic@typoland.com), + * with Reserved Font Name Lato. + * + * This Font Software is licensed under the SIL Open Font License, Version + * 1.1. + * + * This license is copied below, and is also available with a FAQ at: + * http://scripts.sil.org/OFL + */ + +@font-face { + font-family: "Lato"; + font-style: normal; + font-weight: 300; + src: local("Lato Light"), + local("Lato-Light"), + url("fonts/Lato-Light.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: italic; + font-weight: 300; + src: local("Lato Light Italic"), + local("Lato-LightItalic"), + url("fonts/Lato-LightItalic.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: normal; + font-weight: 700; + src: local("Lato Regular"), + local("Lato-Regular"), + url("fonts/Lato-Regular.ttf") format("truetype"); +} + +@font-face { + font-family: "Lato"; + font-style: italic; + font-weight: 700; + src: local("Lato Italic"), + local("Lato-Italic"), + url("fonts/Lato-RegularItalic.ttf") format("truetype"); +} + +/* + * ----------------------------------------------------------- + * SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 + * ----------------------------------------------------------- + * + * PREAMBLE + * The goals of the Open Font License (OFL) are to stimulate worldwide + * development of collaborative font projects, to support the font creation + * efforts of academic and linguistic communities, and to provide a free and + * open framework in which fonts may be shared and improved in partnership + * with others. + * + * The OFL allows the licensed fonts to be used, studied, modified and + * redistributed freely as long as they are not sold by themselves. The + * fonts, including any derivative works, can be bundled, embedded, + * redistributed and/or sold with any software provided that any reserved + * names are not used by derivative works. The fonts and derivatives, + * however, cannot be released under any other type of license. The + * requirement for fonts to remain under this license does not apply + * to any document created using the fonts or their derivatives. + * + * DEFINITIONS + * "Font Software" refers to the set of files released by the Copyright + * Holder(s) under this license and clearly marked as such. This may + * include source files, build scripts and documentation. + * + * "Reserved Font Name" refers to any names specified as such after the + * copyright statement(s). + * + * "Original Version" refers to the collection of Font Software components as + * distributed by the Copyright Holder(s). + * + * "Modified Version" refers to any derivative made by adding to, deleting, + * or substituting -- in part or in whole -- any of the components of the + * Original Version, by changing formats or by porting the Font Software to a + * new environment. + * + * "Author" refers to any designer, engineer, programmer, technical + * writer or other person who contributed to the Font Software. + * + * PERMISSION & CONDITIONS + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of the Font Software, to use, study, copy, merge, embed, modify, + * redistribute, and sell modified and unmodified copies of the Font + * Software, subject to the following conditions: + * + * 1) Neither the Font Software nor any of its individual components, + * in Original or Modified Versions, may be sold by itself. + * + * 2) Original or Modified Versions of the Font Software may be bundled, + * redistributed and/or sold with any software, provided that each copy + * contains the above copyright notice and this license. These can be + * included either as stand-alone text files, human-readable headers or + * in the appropriate machine-readable metadata fields within text or + * binary files as long as those fields can be easily viewed by the user. + * + * 3) No Modified Version of the Font Software may use the Reserved Font + * Name(s) unless explicit written permission is granted by the corresponding + * Copyright Holder. This restriction only applies to the primary font name as + * presented to the users. + * + * 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font + * Software shall not be used to promote, endorse or advertise any + * Modified Version, except to acknowledge the contribution(s) of the + * Copyright Holder(s) and the Author(s) or with their explicit written + * permission. + * + * 5) The Font Software, modified or unmodified, in part or in whole, + * must be distributed entirely under this license, and must not be + * distributed under any other license. The requirement for fonts to + * remain under this license does not apply to any document created + * using the Font Software. + * + * TERMINATION + * This license becomes null and void if any of the above conditions are + * not met. + * + * DISCLAIMER + * THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM + * OTHER DEALINGS IN THE FONT SOFTWARE. + */ + diff --git a/week9/doc/fonts/Lato-Light.ttf b/week9/doc/fonts/Lato-Light.ttf new file mode 100644 index 0000000..b49dd43 Binary files /dev/null and b/week9/doc/fonts/Lato-Light.ttf differ diff --git a/week9/doc/fonts/Lato-LightItalic.ttf b/week9/doc/fonts/Lato-LightItalic.ttf new file mode 100644 index 0000000..7959fef Binary files /dev/null and b/week9/doc/fonts/Lato-LightItalic.ttf differ diff --git a/week9/doc/fonts/Lato-Regular.ttf b/week9/doc/fonts/Lato-Regular.ttf new file mode 100644 index 0000000..839cd58 Binary files /dev/null and b/week9/doc/fonts/Lato-Regular.ttf differ diff --git a/week9/doc/fonts/Lato-RegularItalic.ttf b/week9/doc/fonts/Lato-RegularItalic.ttf new file mode 100644 index 0000000..bababa0 Binary files /dev/null and b/week9/doc/fonts/Lato-RegularItalic.ttf differ diff --git a/week9/doc/fonts/SourceCodePro-Bold.ttf b/week9/doc/fonts/SourceCodePro-Bold.ttf new file mode 100644 index 0000000..61e3090 Binary files /dev/null and b/week9/doc/fonts/SourceCodePro-Bold.ttf differ diff --git a/week9/doc/fonts/SourceCodePro-Regular.ttf b/week9/doc/fonts/SourceCodePro-Regular.ttf new file mode 100644 index 0000000..85686d9 Binary files /dev/null and b/week9/doc/fonts/SourceCodePro-Regular.ttf differ diff --git a/week9/doc/images/add.png b/week9/doc/images/add.png new file mode 100644 index 0000000..6332fef Binary files /dev/null and b/week9/doc/images/add.png differ diff --git a/week9/doc/images/arrow_up.png b/week9/doc/images/arrow_up.png new file mode 100644 index 0000000..1ebb193 Binary files /dev/null and b/week9/doc/images/arrow_up.png differ diff --git a/week9/doc/images/brick.png b/week9/doc/images/brick.png new file mode 100644 index 0000000..7851cf3 Binary files /dev/null and b/week9/doc/images/brick.png differ diff --git a/week9/doc/images/brick_link.png b/week9/doc/images/brick_link.png new file mode 100644 index 0000000..9ebf013 Binary files /dev/null and b/week9/doc/images/brick_link.png differ diff --git a/week9/doc/images/bug.png b/week9/doc/images/bug.png new file mode 100644 index 0000000..2d5fb90 Binary files /dev/null and b/week9/doc/images/bug.png differ diff --git a/week9/doc/images/bullet_black.png b/week9/doc/images/bullet_black.png new file mode 100644 index 0000000..5761970 Binary files /dev/null and b/week9/doc/images/bullet_black.png differ diff --git a/week9/doc/images/bullet_toggle_minus.png b/week9/doc/images/bullet_toggle_minus.png new file mode 100644 index 0000000..b47ce55 Binary files /dev/null and b/week9/doc/images/bullet_toggle_minus.png differ diff --git a/week9/doc/images/bullet_toggle_plus.png b/week9/doc/images/bullet_toggle_plus.png new file mode 100644 index 0000000..9ab4a89 Binary files /dev/null and b/week9/doc/images/bullet_toggle_plus.png differ diff --git a/week9/doc/images/date.png b/week9/doc/images/date.png new file mode 100644 index 0000000..783c833 Binary files /dev/null and b/week9/doc/images/date.png differ diff --git a/week9/doc/images/delete.png b/week9/doc/images/delete.png new file mode 100644 index 0000000..08f2493 Binary files /dev/null and b/week9/doc/images/delete.png differ diff --git a/week9/doc/images/find.png b/week9/doc/images/find.png new file mode 100644 index 0000000..1547479 Binary files /dev/null and b/week9/doc/images/find.png differ diff --git a/week9/doc/images/loadingAnimation.gif b/week9/doc/images/loadingAnimation.gif new file mode 100644 index 0000000..82290f4 Binary files /dev/null and b/week9/doc/images/loadingAnimation.gif differ diff --git a/week9/doc/images/macFFBgHack.png b/week9/doc/images/macFFBgHack.png new file mode 100644 index 0000000..c6473b3 Binary files /dev/null and b/week9/doc/images/macFFBgHack.png differ diff --git a/week9/doc/images/package.png b/week9/doc/images/package.png new file mode 100644 index 0000000..da3c2a2 Binary files /dev/null and b/week9/doc/images/package.png differ diff --git a/week9/doc/images/page_green.png b/week9/doc/images/page_green.png new file mode 100644 index 0000000..de8e003 Binary files /dev/null and b/week9/doc/images/page_green.png differ diff --git a/week9/doc/images/page_white_text.png b/week9/doc/images/page_white_text.png new file mode 100644 index 0000000..813f712 Binary files /dev/null and b/week9/doc/images/page_white_text.png differ diff --git a/week9/doc/images/page_white_width.png b/week9/doc/images/page_white_width.png new file mode 100644 index 0000000..1eb8809 Binary files /dev/null and b/week9/doc/images/page_white_width.png differ diff --git a/week9/doc/images/plugin.png b/week9/doc/images/plugin.png new file mode 100644 index 0000000..6187b15 Binary files /dev/null and b/week9/doc/images/plugin.png differ diff --git a/week9/doc/images/ruby.png b/week9/doc/images/ruby.png new file mode 100644 index 0000000..f763a16 Binary files /dev/null and b/week9/doc/images/ruby.png differ diff --git a/week9/doc/images/tag_blue.png b/week9/doc/images/tag_blue.png new file mode 100644 index 0000000..3f02b5f Binary files /dev/null and b/week9/doc/images/tag_blue.png differ diff --git a/week9/doc/images/tag_green.png b/week9/doc/images/tag_green.png new file mode 100644 index 0000000..83ec984 Binary files /dev/null and b/week9/doc/images/tag_green.png differ diff --git a/week9/doc/images/transparent.png b/week9/doc/images/transparent.png new file mode 100644 index 0000000..d665e17 Binary files /dev/null and b/week9/doc/images/transparent.png differ diff --git a/week9/doc/images/wrench.png b/week9/doc/images/wrench.png new file mode 100644 index 0000000..5c8213f Binary files /dev/null and b/week9/doc/images/wrench.png differ diff --git a/week9/doc/images/wrench_orange.png b/week9/doc/images/wrench_orange.png new file mode 100644 index 0000000..565a933 Binary files /dev/null and b/week9/doc/images/wrench_orange.png differ diff --git a/week9/doc/images/zoom.png b/week9/doc/images/zoom.png new file mode 100644 index 0000000..908612e Binary files /dev/null and b/week9/doc/images/zoom.png differ diff --git a/week9/doc/index.html b/week9/doc/index.html new file mode 100644 index 0000000..78fe963 --- /dev/null +++ b/week9/doc/index.html @@ -0,0 +1,85 @@ + + + + + + +RDoc Documentation + + + + + + + + + + + + + + + + + +
+

This is the API documentation for RDoc Documentation. +

+ + + + + diff --git a/week9/doc/js/darkfish.js b/week9/doc/js/darkfish.js new file mode 100644 index 0000000..06fef3b --- /dev/null +++ b/week9/doc/js/darkfish.js @@ -0,0 +1,140 @@ +/** + * + * Darkfish Page Functions + * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $ + * + * Author: Michael Granger + * + */ + +/* Provide console simulation for firebug-less environments */ +if (!("console" in window) || !("firebug" in console)) { + var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", + "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; + + window.console = {}; + for (var i = 0; i < names.length; ++i) + window.console[names[i]] = function() {}; +}; + + +/** + * Unwrap the first element that matches the given @expr@ from the targets and return them. + */ +$.fn.unwrap = function( expr ) { + return this.each( function() { + $(this).parents( expr ).eq( 0 ).after( this ).remove(); + }); +}; + + +function showSource( e ) { + var target = e.target; + var codeSections = $(target). + parents('.method-detail'). + find('.method-source-code'); + + $(target). + parents('.method-detail'). + find('.method-source-code'). + slideToggle(); +}; + +function hookSourceViews() { + $('.method-heading').click( showSource ); +}; + +function toggleDebuggingSection() { + $('.debugging-section').slideToggle(); +}; + +function hookDebuggingToggle() { + $('#debugging-toggle img').click( toggleDebuggingSection ); +}; + +function hookSearch() { + var input = $('#search-field').eq(0); + var result = $('#search-results').eq(0); + $(result).show(); + + var search_section = $('#search-section').get(0); + $(search_section).show(); + + var search = new Search(search_data, input, result); + + search.renderItem = function(result) { + var li = document.createElement('li'); + var html = ''; + + // TODO add relative path to + + + + + + + + + + +
+

Table of Contents - RDoc Documentation

+ + +

Classes and Modules

+ + +

Methods

+ +
+ + + + diff --git a/week9/exceptions.rb b/week9/exceptions.rb new file mode 100644 index 0000000..9d18ade --- /dev/null +++ b/week9/exceptions.rb @@ -0,0 +1,31 @@ +class ReneeError < Exception + def message + "Renee breaks everything" + end +end + +def hello + begin + raise ReneeError.new + puts yield + rescue LocalJumpError => e + puts e + rescue ReneeError => e + puts e + puts "Don't let Renee near your code" + ensure + puts "you ran the hello method" + end + + catch :renee_error do + puts "before throw" + throw :renee_error + puts "after throw" + end + puts "after method" +end + + +hello { " Hello Akichin "} + +hello \ No newline at end of file diff --git a/week9/rdoc_demo.rb b/week9/rdoc_demo.rb new file mode 100644 index 0000000..7b7fd5e --- /dev/null +++ b/week9/rdoc_demo.rb @@ -0,0 +1,21 @@ +class HeadGear +end + +# This is a really cool Hat class +# +# Author: Chris Ashfield +# License: MIT +# +# More info about class +class Hat < HeadGear + attr_accessor :color, :size + + # This is the constructor + # * size : the size of the Hat + # * color : The color of the Hat + def initialize color, size + @color = color + @size = size + end + +end \ No newline at end of file diff --git a/week9/sinatra_test.rb b/week9/sinatra_test.rb new file mode 100644 index 0000000..047743d --- /dev/null +++ b/week9/sinatra_test.rb @@ -0,0 +1,22 @@ +require 'sinatra' +require 'thin' + +get '/hello' do + hez do |aa| + "Hello World
+ The time is #{aa} +
" + end +end + +get '/' do + " + HOME

+ link + " +end + +def hez + time = Time.now + yield time +end