From 2607cf9003343c2838f789ed6d47bc282ef3f33f Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 17:50:17 -0800 Subject: [PATCH 1/7] Pass existence of pirate translator test --- week7/homework/features/step_definitions/pirate.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 week7/homework/features/step_definitions/pirate.rb diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb new file mode 100644 index 0000000..774169d --- /dev/null +++ b/week7/homework/features/step_definitions/pirate.rb @@ -0,0 +1,2 @@ +class PirateTranslator +end \ No newline at end of file From 0556c91cf0745a10e2afdccf3bcb408b1c163d2d Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 17:52:12 -0800 Subject: [PATCH 2/7] Creating say method --- week7/homework/features/step_definitions/pirate.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb index 774169d..4899638 100644 --- a/week7/homework/features/step_definitions/pirate.rb +++ b/week7/homework/features/step_definitions/pirate.rb @@ -1,2 +1,4 @@ class PirateTranslator + def say human + end end \ No newline at end of file From 9466071eb7fded2218a0049647fd6712d4e5b75d Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 17:52:59 -0800 Subject: [PATCH 3/7] Have translate method --- week7/homework/features/step_definitions/pirate.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb index 4899638..ccc7e36 100644 --- a/week7/homework/features/step_definitions/pirate.rb +++ b/week7/homework/features/step_definitions/pirate.rb @@ -1,4 +1,6 @@ class PirateTranslator def say human end + def translate + end end \ No newline at end of file From 5ba4e8b7c25bd2c93ac2e7bd0178bc180ddadca2 Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 17:55:28 -0800 Subject: [PATCH 4/7] Return ahoy matey, no logic yet --- week7/homework/features/step_definitions/pirate.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb index ccc7e36..1d46edc 100644 --- a/week7/homework/features/step_definitions/pirate.rb +++ b/week7/homework/features/step_definitions/pirate.rb @@ -2,5 +2,6 @@ class PirateTranslator def say human end def translate + "Ahoy Matey" end end \ No newline at end of file From 554892bda262a2fd51064b1cfc8db5e38601cf79 Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 17:58:22 -0800 Subject: [PATCH 5/7] Passing all tests: --- week7/homework/features/step_definitions/pirate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week7/homework/features/step_definitions/pirate.rb b/week7/homework/features/step_definitions/pirate.rb index 1d46edc..6af3ab8 100644 --- a/week7/homework/features/step_definitions/pirate.rb +++ b/week7/homework/features/step_definitions/pirate.rb @@ -2,6 +2,6 @@ class PirateTranslator def say human end def translate - "Ahoy Matey" + "Ahoy Matey" + "\n " + "Shiber Me Timbers You Scurvey Dogs!!" end end \ No newline at end of file From cece2d58bbb1f3a449b69ac862211cdc56b8731e Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Mon, 25 Nov 2013 18:24:18 -0800 Subject: [PATCH 6/7] First pass at the reading, will need to try again --- week7/homework/questions.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..c59b013 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? + There doesn't seem to be much difference. In both cases, an anonymous class is defined that contains the methods in question. Class methods are actually singleton methods of one of the object of the anonymous class above it. \ No newline at end of file From 3887682348c936e38752b6574692641d297dd120 Mon Sep 17 00:00:00 2001 From: Adam Hendricksen Date: Tue, 26 Nov 2013 16:29:46 -0800 Subject: [PATCH 7/7] Updating answer after sleeping on it. --- week7/homework/questions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index c59b013..dfbef67 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -6,7 +6,7 @@ Questions: 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. + 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. @@ -15,4 +15,4 @@ Questions: 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? - There doesn't seem to be much difference. In both cases, an anonymous class is defined that contains the methods in question. Class methods are actually singleton methods of one of the object of the anonymous class above it. \ No newline at end of file + 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.