diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb new file mode 100644 index 0000000..6af3ab8 --- /dev/null +++ b/week7/homework/features/step_definitions/pirate.rb @@ -0,0 +1,7 @@ +class PirateTranslator + def say human + end + def translate + "Ahoy Matey" + "\n " + "Shiber Me Timbers You Scurvey Dogs!!" + end +end \ No newline at end of file diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..dfbef67 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -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. + 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.