This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Includes work to date for final #115
Open
davejlane
wants to merge
17
commits into
UWE-Ruby:master
Choose a base branch
from
davejlane:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1086498
The questions and tests were answered and updated so that they can be…
445b0d7
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
91c23b9
Completed questions and test for week 2
db3d085
Module to test against
646abaf
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
c9ea8db
Completed homework for week3
121db55
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
0b62619
Week 4 homework
541c27b
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
2209a3a
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
0cbb448
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
f28f5a2
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
0c3ef7e
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
a8b2af4
week7 homework
9f5f6c7
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
42b808c
Merge branch 'master' of https://github.com/UWE-Ruby/RubyFall2013
7aa76a4
Work to date for tic tac toe game
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
Please Read The Chapters on: | ||
Containers, Blocks, and Iterators | ||
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? | ||
|
||
While there are some simlilariies between an Array and a Hash, in that they are both indexed collections of object references, the main difference is that an Array is indexed using integers, while a Hash is indexed using objects of any type, for example strings or symbols. | ||
|
||
2. When would you use an Array over a Hash and vice versa? | ||
|
||
You would use an Array over a Hash when you're unable, or do not know what type of object you will be using to index the contents. | ||
You would use an Array over a Hash when you require an integer key to index the contents. | ||
You would use a Hash over an Array when you need to use objects as indices. | ||
You would use a Hash over an Array when it is important to keep track of the order in which the items were entered into the Hash. (Ruby returns them in the order in which they were received). | ||
|
||
|
||
3. What is a module? Enumerable is a built in Ruby module, what is it? | ||
|
||
A module is a way of grouping together methods, classes and contstants. They also provide a way to nampespace their contents, which is helpful in avoiding naming clashes. Modules are also usefule in that things that would not necessarialy form a class can be grouped together. | ||
|
||
Enumerable is a mixin module, which supplies the class that requires it to with a number of methods that allow the class to traverse, sort and search it's contents, as long as the class in question provides an each(iterator) method. | ||
|
||
4. Can you inherit more than one thing in Ruby? How could you get around this problem? | ||
|
||
Ruby is a single-inheritance language, so a class has only one direct parent. However, a class in Ruby can include and use any number of mixins, which are like partial class definitions. So while a Ruby class has only one direct parent, it can behave like a class that supports multiple inheritance without the dangers that surround the kind of ambiguity that multiple inheritance can provide. | ||
|
||
5. What is the difference between a Module and a Class? | ||
|
||
A Module cannot have instances, as it is not a Class. A Module does not require instantiation, whereas a Class does. A Class has access to it's own intance variables, wheras a Module has access to any instance varibales of the Class it has been included in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module SimonSays | ||
def echo(name) | ||
return name | ||
end | ||
|
||
def shout(name) | ||
return name.upcase | ||
end | ||
|
||
def repeat(name, n) | ||
Array.new(n, name).join ' ' | ||
end | ||
|
||
def start_of_word(name, n) | ||
@frag = name.scan /\w/ | ||
return @frag[0...n].join'' | ||
end | ||
|
||
def first_word(name) | ||
return name.split(" ")[0] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Calculator | ||
|
||
def sum *values | ||
values.flatten! | ||
values.inject(0) { |val, i| val += i } | ||
end | ||
|
||
def multiply *values | ||
values.flatten! | ||
values.inject(1) { |val, i| val *= i } | ||
end | ||
|
||
def pow base, multiplier | ||
values = Array.new multiplier, base | ||
values.flatten! | ||
values.inject(1) {|val, i| val *= i } | ||
end | ||
|
||
def fac value | ||
value == 0 ? 1 : value * fac(value-1) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
Please Read: | ||
Please Read: | ||
- Chapter 6 Standard Types | ||
- Review Blocks | ||
- Chapter 7 Regular Expressions | ||
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants | ||
|
||
1. What is a symbol? | ||
A symbol is an identifier that you use to represent to a string or a name. | ||
|
||
2. What is the difference between a symbol and a string? | ||
Strings are immutable, while symbols are not. Also, symbols can accept interpolation, where a string literal cannot. | ||
|
||
3. What is a block and how do I call a block? | ||
A block is a set of statements and expressions that are wrapped in either braces or a do/end pair. The block immediately follows a method invocation, for example, after the .each method is calling a block here: | ||
|
||
[1,2,3,4].each do |value| | ||
#block goes here | ||
end | ||
|
||
4. How do I pass a block to a method? What is the method signature? | ||
You pass a block to a method by using the yield statement in a method that has the same name as the block. For example: | ||
def test | ||
yield | ||
end | ||
test{ puts "Hello world"} | ||
|
||
You can also pass the block into a method by passing it as the last argument of the method, and by prepending & to the block name. For example: | ||
|
||
def test(&block) | ||
block.call | ||
end | ||
test { puts "Hello World!"} | ||
|
||
|
||
5. Where would you use regular expressions? | ||
Anywhere that we would want to match, extract or changes a string based upon a given pattern. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Worker | ||
|
||
def self.work (repeat_count=1) | ||
i = nil | ||
repeat_count.times {i = yield} | ||
i | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
Please Read: | ||
Please Read: | ||
Chapter 10 Basic Input and Output | ||
The Rake Gem: http://rake.rubyforge.org/ | ||
|
||
1. How does Ruby read files? | ||
|
||
Ruby reads files through I/0 -related methods that exist in the Kernel module. THese methods include, gets, open, print, printf, putc, puts, readline and test, which are all used to open and close files, as well as read the files' data and write to the file. | ||
|
||
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 Dir class is used as a way or representing directory structures and their contents. This class allows us to manipulate the directory and file structure, search for, rename, delete and create files and directories. | ||
|
||
|
||
4. What is an IO object? | ||
|
||
An IO object is a class that gives a bidirectional channel between a Ruby program and an external resource. The IO object can be written to and read from. | ||
|
||
5. What is rake and what is it used for? What is a rake task? | ||
|
||
Rake is used to build executable programs and libraries from source code. A rake task is an instruction in the form of code that is executed when running rake. A task may be grouped with other tasks, and contain dependencies to other files or tasks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class PirateTranslator | ||
def say(statement) | ||
puts statement | ||
end | ||
|
||
def translate(statement = '') | ||
"Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good!