diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fc0df50 Binary files /dev/null and b/.DS_Store differ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..e061e30 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format nested +--color \ No newline at end of file diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt deleted file mode 100644 index bd581a6..0000000 --- a/week1/homework/questions.txt +++ /dev/null @@ -1,15 +0,0 @@ -Please read: -Chapter 3 Classes, Objects, and Variables -p.86-90 Strings (Strings section in Chapter 6 Standard Types) - -1. What is an object? - -2. What is a variable? - -3. What is the difference between an object and a class? - -4. What is a String? - -5. What are three messages that I can send to a string object? Hint: think methods - -6. What are two ways of defining a String literal? Bonus: What is the difference between the two? diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb deleted file mode 100644 index ea79e4c..0000000 --- a/week1/homework/strings_and_rspec_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# 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 - diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt deleted file mode 100644 index 939e42d..0000000 --- a/week2/homework/questions.txt +++ /dev/null @@ -1,13 +0,0 @@ -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? - -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? - -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? diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..971a674 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,21 @@ +module SimonSays + def echo(st) + st + end + + def shout(st) + st.upcase + end + + def first_word(st) + st.split.first + end + + def start_of_word(st,i) + st[0...i] + end + + def repeat(st, t=2) + ([st]*t).join(' ') + end +end diff --git a/week4/.DS_Store b/week4/.DS_Store new file mode 100644 index 0000000..457080e Binary files /dev/null and b/week4/.DS_Store differ diff --git a/week4/exercises/.rspec b/week4/exercises/.rspec new file mode 100644 index 0000000..e061e30 --- /dev/null +++ b/week4/exercises/.rspec @@ -0,0 +1,2 @@ +--format nested +--color \ No newline at end of file diff --git a/week4/exercises/worker_spec.rb b/week4/exercises/worker_spec.rb index dfc6f02..47deddb 100644 --- a/week4/exercises/worker_spec.rb +++ b/week4/exercises/worker_spec.rb @@ -1,4 +1,5 @@ -require "#{File.dirname(__FILE__)}/worker" +#require "#{File.dirname(__FILE__)}/worker" +require File.join(File.dirname(__FILE__), '..', '/homework/worker') describe Worker do diff --git a/week4/homework/.DS_Store b/week4/homework/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/week4/homework/.DS_Store differ diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index bc1ab7c..80226e3 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,7 +3,40 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? +Ruby defines a single base class, IO, to handle input and output. The same +methods we use for 'simple' i/o from irb, puts, gets, are available for all file +objects: + while line = gets + puts line + end +There are I/O iterators for reading. I/O#each_byte invokes a block with next 8-bit +byte from the IO object. String#dump can also be used + File.open("tesfile") do |file| + file.each_line {|line| puts "got #{line.dump}"} + end + 2. How would you output "Hello World!" to a file called my_output.txt? + + File.open("output.txt", "w") do |file| + file.puts "Hello World!" + end + 3. What is the Directory class and what is it used for? + +Objects of class Dir are directory streams representing directories in the +underlying file system. They provide a variety of ways to list directories and +their contents. + 4. What is an IO object? + +Ruby defines a single base class, IO, to handle input and output. An IO object is +a bidirectional channel between a Ruby program and some external resource. Bidirectional +as in read/write, puts/gets. + + 5. What is rake and what is it used for? What is a rake task? +Rake is a simple ruby build program with capabilities similar to 'make.' Tasks or jobs can be written in ruby +and executed via the ruby Rake command. Files containg ruby code can also be part of the execution. In rails, +rake db:migrate is used to run a database migration script that executes ruby code to build tables according +to the database and table specifications. To view the 'routes' that a ruby application may be configured to run, +the 'rake routes' command will display what the ruby program or application will respond to. diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..051d1aa --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,17 @@ +class Worker + def self.work (number = 1) + result = '' + number.times {result = yield if block_given?} + result + end + + #or + + ##class << self + ## def work number=1 + ## result = '' + ## number.times {result = yield if block_given?} + ## result + ## end + ##end +end diff --git a/week5/Rakefile.rb b/week5/Rakefile.rb new file mode 100644 index 0000000..724c307 --- /dev/null +++ b/week5/Rakefile.rb @@ -0,0 +1,66 @@ +##task :default => [:hello_world] +## desc "This outputs..." +## task :hello_world do +## puts "hellow World!" +## test +## end +## +## def test +## "tequila" +## end + +#task #:default => [:readnames] + desc "read names" + task :readnames do + File.open("names.rb") do |f| + File.open('outnames.rb','w') do |out| + f.each do |line| + puts line + #out << line + end + end + end + #Dir.mkdir("test") + end + desc "mkdir" + task :makedir do + Dir.mkdir("testdir") + end +###desc "print..." +###task :print_names do +### file.open("names") do |f| +### f.map{|def line( puts line} +### +### end +### } +### +###task :create_student_dirs => [:create_class_dir] do +### +### f.map +### +### dir +### rake print_names +### +### create a helper +### +### file_helper("../name") do |line| +### puts line +### end +### +### file_helper("../name") do |line| +### Dir.mkdir line +### end +### +### file_helper("../name") do |line| +### Dir.rmdir line +### end +### +###def file_helper(file_name) +### File.open(file_name) do |f| +### f.each do \line| +### yield line.chomp #chomp carriage return +### +### end +### end +###end +###end \ No newline at end of file diff --git a/week5/names.rb b/week5/names.rb new file mode 100644 index 0000000..1b0e842 --- /dev/null +++ b/week5/names.rb @@ -0,0 +1,35 @@ +Ben +BrianT +BrianWard +BryanWilliams +Cheri +Chris B +ChristopherF +ChristopherT +Danny +Dimitry +Eddie +Emily +Gregory +Josh +Karen +Kat +Kelli +Kris +Mallory +Nell +NicholasP +Nicole +Nikky +Peter +Price +Renée +Ryan +Santy +Serene +Sol +Steven +Strand +Timothy +Will +Yan \ No newline at end of file diff --git a/week5/outnames.rb b/week5/outnames.rb new file mode 100644 index 0000000..e69de29