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

Answers #105

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format nested
--color
15 changes: 0 additions & 15 deletions week1/homework/questions.txt

This file was deleted.

26 changes: 0 additions & 26 deletions week1/homework/strings_and_rspec_spec.rb

This file was deleted.

13 changes: 0 additions & 13 deletions week2/homework/questions.txt

This file was deleted.

21 changes: 21 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added week4/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions week4/exercises/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format nested
--color
3 changes: 2 additions & 1 deletion week4/exercises/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Binary file added week4/homework/.DS_Store
Binary file not shown.
33 changes: 33 additions & 0 deletions week4/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 17 additions & 0 deletions week4/homework/worker.rb
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions week5/Rakefile.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions week5/names.rb
Original file line number Diff line number Diff line change
@@ -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
Empty file added week5/outnames.rb
Empty file.