From 8017008322e5cf915cb269a8b6ac7fb7a0d64d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Mota?= Date: Fri, 3 May 2013 21:12:22 +0100 Subject: [PATCH] Pull Up Method. --- pull-up-method/lib/after.rb | 24 ++++++++++++++++++++++++ pull-up-method/lib/before.rb | 29 +++++++++++++++++++++++++++++ pull-up-method/test/test.rb | 12 ++++++++++++ 3 files changed, 65 insertions(+) diff --git a/pull-up-method/lib/after.rb b/pull-up-method/lib/after.rb index e69de29..5f7aeaf 100644 --- a/pull-up-method/lib/after.rb +++ b/pull-up-method/lib/after.rb @@ -0,0 +1,24 @@ +class Person + attr_reader :first_name, :last_name + + def initialize first_name, last_name + @first_name = first_name + @last_name = last_name + end + + def full_name + first_name + " " + last_name + end +end + +class MalePerson < Person + def gender + "M" + end +end + +class FemalePerson < Person + def gender + "F" + end +end diff --git a/pull-up-method/lib/before.rb b/pull-up-method/lib/before.rb index e69de29..02796a4 100644 --- a/pull-up-method/lib/before.rb +++ b/pull-up-method/lib/before.rb @@ -0,0 +1,29 @@ +class Person + attr_reader :first_name, :last_name + + def initialize first_name, last_name + @first_name = first_name + @last_name = last_name + end + +end + +class MalePerson < Person + def full_name + first_name + " " + last_name + end + + def gender + "M" + end +end + +class FemalePerson < Person + def full_name + first_name + " " + last_name + end + + def gender + "F" + end +end diff --git a/pull-up-method/test/test.rb b/pull-up-method/test/test.rb index a8f6974..180f890 100644 --- a/pull-up-method/test/test.rb +++ b/pull-up-method/test/test.rb @@ -3,3 +3,15 @@ require 'before' if ENV["BEFORE"] require 'after' unless ENV["BEFORE"] + +describe MalePerson do + it "has a full name" do + MalePerson.new("John", "Smith").full_name.must_equal "John Smith" + end +end + +describe MalePerson do + it "has a full name" do + FemalePerson.new("Michelle", "Smith").full_name.must_equal "Michelle Smith" + end +end