From 660ea8a0aed6adb98f95ebec7656a1121797b182 Mon Sep 17 00:00:00 2001 From: Chris Montes Date: Tue, 8 Oct 2013 19:30:13 -0700 Subject: [PATCH 1/5] Adds info for Chris Montes --- week1/exercises/roster.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week1/exercises/roster.txt b/week1/exercises/roster.txt index 5c431bf..d1caa8f 100644 --- a/week1/exercises/roster.txt +++ b/week1/exercises/roster.txt @@ -1,5 +1,5 @@ #, name, email, github, twitter, chat -0, +0, 1, 2, 3, @@ -18,7 +18,7 @@ 16, 17, 18, -19, +19, Chris Montes, chrismontes@about.me, mandelbro, chrismontes, chrismontes 20, 21, 22, @@ -32,4 +32,4 @@ 30, 31, 32, -33, \ No newline at end of file +33, \ No newline at end of file From ce04b63d2c0becf063dc573e21054e199d5fb38b Mon Sep 17 00:00:00 2001 From: Chris Montes Date: Tue, 22 Oct 2013 12:33:43 -0700 Subject: [PATCH 2/5] Adds in class work --- week2/exercises/book.rb | 14 +++++++++----- week2/exercises/book_spec.rb | 31 +++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/week2/exercises/book.rb b/week2/exercises/book.rb index 50bc054..a3791e4 100644 --- a/week2/exercises/book.rb +++ b/week2/exercises/book.rb @@ -1,13 +1,17 @@ class Book - attr_accessor :title, :pages + attr_accessor :title, :page_count - def initialize(title, pages) + def initialize(title, page_count) @title = title - @pages = pages + @page_count = page_count end - def page_count - "Page count is #{@pages}" + def pages + "Page count is #{@page_count}" end + + def ╯°□°╯︵┻━┻ + "FUUUUUUUUU" + end end diff --git a/week2/exercises/book_spec.rb b/week2/exercises/book_spec.rb index bb22819..7a135f3 100644 --- a/week2/exercises/book_spec.rb +++ b/week2/exercises/book_spec.rb @@ -1,14 +1,25 @@ require './book.rb' +# describe the Book class describe Book do - before :each do - @book = Book.new("Harry Potter", 200) - end - it "should respond to title" do - @book.should respond_to "title" - end - - it "should return the page count" do - @book.page_count.should eq "Page count is 200" - end + + before :each do + @book = Book.new("Harry Potter", 200) + end + + it "should have a title" do + @book.should respond_to(:title) + @book.should_not be_nil + end + + it "should have page count" do + @book.should respond_to(:page_count) + @book.page_count.should be_integer + @book.page_count.should be > 0 + end + + it "should FUUUUUUUUUUU" do + @book.should respond_to(:╯°□°╯︵┻━┻) + end + end From dc37ef95971eef79fe629b76d487960da2e214e0 Mon Sep 17 00:00:00 2001 From: Chris Montes Date: Tue, 26 Nov 2013 14:01:31 -0800 Subject: [PATCH 3/5] Adds converter answers for week 7 homework --- .../features/step_definitions/converter.rb | 19 +++++++++++++++++++ .../step_definitions/converter_steps.rb | 15 +++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 week7/exercises/features/step_definitions/converter.rb create mode 100644 week7/exercises/features/step_definitions/converter_steps.rb diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..7542268 --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,19 @@ + +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.0) / (9.0/5.0)).round(1) + end +end diff --git a/week7/exercises/features/step_definitions/converter_steps.rb b/week7/exercises/features/step_definitions/converter_steps.rb new file mode 100644 index 0000000..8deed91 --- /dev/null +++ b/week7/exercises/features/step_definitions/converter_steps.rb @@ -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 \ No newline at end of file From c275e059d538e3120c8a0deefde935dc13fa91b2 Mon Sep 17 00:00:00 2001 From: Chris Montes Date: Tue, 26 Nov 2013 14:02:54 -0800 Subject: [PATCH 4/5] Adds PirateTranslator class for week 7 homework --- .../step_definitions/piarate_translator.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 week7/homework/features/step_definitions/piarate_translator.rb diff --git a/week7/homework/features/step_definitions/piarate_translator.rb b/week7/homework/features/step_definitions/piarate_translator.rb new file mode 100644 index 0000000..2e2a9eb --- /dev/null +++ b/week7/homework/features/step_definitions/piarate_translator.rb @@ -0,0 +1,16 @@ + +class PirateTranslator + + @@dictionary = { + "Hello Friend" => "Ahoy Matey\n Shiber Me Timbers You Scurvey Dogs!!" + } + + def say(text) + @text = text + end + + def translate + @@dictionary[@text] + end + +end From f4ca2a66c1b3cf109afa0d4b6948ca80f692637b Mon Sep 17 00:00:00 2001 From: Chris Montes Date: Tue, 26 Nov 2013 14:03:11 -0800 Subject: [PATCH 5/5] Adds question responses from reading for week 7 homework --- week7/homework/questions.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..9a7cb48 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -2,8 +2,23 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming Questions: + 1. What is method_missing and how can it be used? + +method_missing is a Ruby hook method that runs when a method has been sent to an object that is unsupported by it or it's parent classes. Essentially it is used to handle calls to undefined methods, which is useful for implementing features of a dynamic frame, like objects with dynamic accessors, i.e., allowing users to dynamically add properties to a class instance. Another implementation would be providing optional methods or hook callbacks withing a framework or CMS. + 2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? + +Eiganclass is an anonymous class created to when a singleton method is added to an object instance. The Eigenclass class extends the object's original class, and the object becomes an instance of the Eigenclass. The singelton method lives inside this class. A common implementation of this is with macros like 'attr_accessor' or 'has_many' relationship macro in Rails, where the macro defines singleton methods based on the arguments passed to it. + 3. When would you use DuckTypeing? How would you use it to improve your code? + +Ducktyping is useful in dynamic typed languages, where objects are defined by their purpose rather than their type. I would use it to make my functions more robust, i.e., better able to handle a wide array of inputs, more simple, one or two lines of code rather than complicated if/else or switch statements, and to take advantage of making my class more efficient and easy to use by allowing users to pass, say, entire loaded objects OR numeric or string identifies. + 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 methods that can be called directly on classes, e.g., ClassName.new, but not by instances of a class, while instance methods only be called on an instance of a class, e.g., object.doSomething, but not on the class itself. The methods 'instance_eval' defines class methods, while 'class_eval' defines instance methods. As you would expect. + 5. What is the difference between a singleton class and a singleton method? + +A singleton method is a method of the singleton class, the class that is created to support the singleton method when the method is defined. \ No newline at end of file