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

Homework 7 #116

Open
wants to merge 7 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
7 changes: 7 additions & 0 deletions week7/homework/features/step_definitions/pirate.rb
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
9 changes: 9 additions & 0 deletions week7/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

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.


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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good.