This repository was 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
Week7 homework for Sean Sehr #114
Open
seansehr
wants to merge
2
commits into
UWE-Ruby:master
Choose a base branch
from
seansehr:week7
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Converter | ||
|
||
def initialize(unit) | ||
@unit = unit.to_f | ||
end | ||
|
||
def type=(type) | ||
@type = type | ||
end | ||
|
||
def convert | ||
self.send("#{@type}_convertion") | ||
end | ||
|
||
def Fahrenheit_convertion | ||
((@unit - 32) * 5/9).round(1) | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
week7/exercises/features/step_definitions/converter_steps.rb
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,15 @@ | ||
Given(/^I have entered (\d+) into the converter$/) do |arg1| | ||
@converter = Converter.new(arg1) | ||
end | ||
|
||
Given(/^I set the type to Fahrenheit$/) do | ||
@converter.type = "Fahrenheit" | ||
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 |
17 changes: 17 additions & 0 deletions
17
week7/homework/features/step_definitions/pirate_translator.rb
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,17 @@ | ||
class PirateTranslator | ||
attr_accessor :phrases | ||
|
||
def initialize | ||
@phrases = { | ||
"Hello Friend" => "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!" | ||
} | ||
end | ||
|
||
def say text | ||
@text = text | ||
end | ||
|
||
def translate | ||
@phrases[@text] | ||
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 |
---|---|---|
|
@@ -3,7 +3,16 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming | |
|
||
Questions: | ||
1. What is method_missing and how can it be used? | ||
The method_messing is used when an object executes the method, but the method is not found. It is ran instead of a NoMethodError exception. The method_missing method is passed the symbol of the non-existent method, an array of the arguments that were passed in the original call and any block passed to the original method. | ||
|
||
2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? | ||
An Eigenclass is the anonymous class that is created when you define a Singleton method on an object. It is used to hold the new method and the original class as the superclass.Singleton methods live inside this Eigenclass | ||
|
||
3. When would you use DuckTypeing? How would you use it to improve your code? | ||
I would use DuckTypeing when working in dynamic languages that do not have strong typing (Ruby, Javascript, etc). I would use to make my code more flexable and futureproof. | ||
|
||
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 ran on the class themselves while instances methods are ran on that particular instance. If you create a new instance of a class the class method will not work. Attempting to run a class method on an instance will also not work. A class method is for anything that does not deal with an individual instance of a class. instance_eval is used to dfine a class method while class_eval is used ot define an instance method. | ||
|
||
5. What is the difference between a singleton class and a singleton method? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A singleton method is a method that is specific to a particular object (as opposed to a class). |
||
A singleton class effects all instances of that class, a singleton method only effects the single instance. |
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.
Perfect!