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
Homework 7 #116
Open
vogelbek
wants to merge
7
commits into
UWE-Ruby:master
Choose a base branch
from
vogelbek:Homework_7
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
Homework 7 #116
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2607cf9
Pass existence of pirate translator test
vogelbek 0556c91
Creating say method
vogelbek 9466071
Have translate method
vogelbek 5ba4e8b
Return ahoy matey, no logic yet
vogelbek 554892b
Passing all tests:
vogelbek cece2d5
First pass at the reading, will need to try again
vogelbek 3887682
Updating answer after sleeping on it.
vogelbek 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,7 @@ | ||
class PirateTranslator | ||
def say human | ||
end | ||
def translate | ||
"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
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? | ||
It is automatically called when a method is called on a class where it isn't defined. The default is that it should then search the parent class to see if it's there (possibly tripping that method_missing). At the top of the tree, Object throws an error if method_missing is called. | ||
|
||
2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? | ||
An Eigenclass (or Singleton class) is an anonomous class that hosts the Singleton methods defined for a particular object. It is itself a child of the class that the object would be a child of. | ||
|
||
3. When would you use DuckTypeing? How would you use it to improve your code? | ||
I can imagine having a method adding content to the end of a string, but it might be reusable to append an array. So long as my code is still readable, it is good to maintain less code. | ||
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. Many data types can respond to the same message (method). That's cool! |
||
|
||
4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? | ||
The class method is applied for the entire collection of class objects, whereas an instance method is only applicable for a particular object. | ||
|
||
5. What is the difference between a singleton class and a singleton method? | ||
A singleton method is defined on a particular object. A singleton class is the parent class created automatically to host the singleton methods of the particular object. | ||
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. Very good. |
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.
method_missing is the method that Ruby looks for after it can't find the method that's been called anywhere in the class hierarchy that it was called in.