Skip to content

Commit

Permalink
Pull Up Method.
Browse files Browse the repository at this point in the history
  • Loading branch information
josemotanet committed Jun 4, 2013
1 parent 49e3e1a commit 8017008
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pull-up-method/lib/after.rb
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions pull-up-method/lib/before.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions pull-up-method/test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8017008

Please sign in to comment.